This package computes the memory usage of a gretl object. The package comprises seven public functions for computing memory usage (in megabytes) of either a series, a list of series, a matrix, an array of matrices, a string, an array of strings and all items of a bundle comprising different data types.
pkg install memusage # download from package server
clear
set verbose off
include memusage.gfn # load functions into memory
# Define various objects differing in their data types
strings S = defarray("S1", "S2")
matrix m = ones(10^5, 32)
matrices M = defarray(ones(10^5, 32), ones(3,2))
string web_page = readfile("http://gretl.sourceforge.net/")
bundle b = defbundle("S", S, "m", m, "web_page", web_page, "LRM", LRM)
list L = LRM LRY IDE IBO
# Call the generic function consuming a bundle with various variables
scalar mem = memusage(b, TRUE) # returns total memory of all bundle items
print mem
The printout is as follows:
Info: Size of strings : 1.52588e-05 MB.
Info: Size of matrix : 24.4141 MB.
Info: Size of series : 0.000419617 MB.
Info: Size of string : 0.133804 MB.
Info: Size of bundle b: 24.5483 MB.
24.548302
and scalar mem
refers to the value 24.5483
.
Function: memusage()
Arguments:
- bundle, input bundle
- bool, print value in megabytes
Output:
- scalar, memory use in megabytes
Return:
- Computes the memory usage of all items of a bundle in megabytes.
Function: memusage_matrix()
Arguments:
- matrix, input matrix
- bool, print value in megabytes
Output:
- scalar, memory use in megabytes
Return:
- Computes the memory usage of a matrix in megabytes.
Function: memusage_matrices()
Arguments:
- matrices, input array of matrices
- bool, print value in megabytes
Output:
- scalar, memory use in megabytes
Return:
- Computes the memory usage of an array of matrices in megabytes.
Function: memusage_series()
Arguments:
- series, input series
- bool, print value in megabytes
Output:
- scalar, memory use in megabytes
Return:
- Computes the memory usage of a series in megabytes.
Function: memusage_list()
Arguments:
- list, list of series
- bool, print value in megabytes
Output:
- scalar, memory use in megabytes
Return: 'Computes the memory usage of a list of series in megabytes.
Function: memusage_string()
Arguments:
- string, input string
- bool, print value in megabytes
Output:
- scalar, memory use in megabytes
Return:
- Computes the memory usage of a string in megabytes. Note: If unicode formats is ASCII, the memory usage is one byte per character; if UTF-8 it depends, at least one byte but up to 4 per character. We will always assume one by per character.
Function: memusage_strings()
Arguments:
- strings, array of input strings
- bool, print value in megabytes
Output:
- scalar, memory use in megabytes
Return:
- Computes the memory usage of an array of strings in megabytes. Note: If unicode formats is ASCII, the memory usage is one byte per character; if UTF-8 it depends, at least one byte but up to 4 per character. We will always assume one by per character.
- v1.0, June 2020:
- initial release