memory(int mode): size_t
Returns the current memory consumption of the script.
Parameters:
mode -
0: Current total memory allocation
in bytes, including virtual memory and cache pages that have been written to.
1: Sum of all memory allocations in bytes by functions, price data, and series during the script run.
2: Current number of allocated memory areas by functions, price data, and series.
4: Memory allocation in bytes per asset for historical price
data.
Returns:
See mode.
Remarks:
- Divide by 1024 for getting kBytes and by (1024*1024) for getting
MBytes.
- This function was reported not to return the correct memory allocation under Linux/Wine with mode == 0.
- Assets, bars, series, trades, and charts consume memory. The memory requirement
per asset
in bytes can be estimated with the formula Years / BarPeriod * 15 MB,
where Years is the number of backtest years including the
LookBack period (use 1
for live trading). The LEAN and LEANER
flags reduce the memory requirement by about 50%, the TICKS
flag increases it by 32 bytes per historical price tick.
Series allocate 8 bytes per element and asset,
plot commands allocate 8..24 bytes per bar and asset.
- For backtests with large memory requirement, use Zorro64.
Example:
function run()
{
BarPeriod = 1;
LookBack = 1;
...
printf("\rMemory %i areas %i kb",memory(2),memory(0)/1024);
plot("Memory",memory(0),NEW,RED);
}
See Also:
timer, malloc,
zalloc
► latest
version online