I'm talking about memory reserved using the third parameter of the ArrayResize function. Is there a way to find out how much memory is reserved for an array?
Aren't you suppose to know it from your own code ?
I wanted to do a couple of tests to make sure that I understand correctly how memory reservation works😄
Usually the reserve size is known at compile time (does not change at runtime). In this case, no questions arise. But there are doubts if the reserve size is calculated at runtime.
Am I understanding correctly that the code below will not reserve memory?
void OnStart() { double arr[]; ArrayResize(arr, 0, 1000); }
Am I understanding correctly that a highlighted line will not reduce the reserved memory?
void OnStart() { double arr[]; ArrayResize(arr, 1, 1000); ArrayResize(arr, 2, 100); }
Looks like I found a way to find out (not very convenient).
Am I understanding correctly that the code below will not reserve memory?
void OnStart() { double arr[]; Print("Before: ", TerminalInfoInteger(TERMINAL_MEMORY_USED)); ArrayResize(arr, 0, 1000000); Print("0: ", TerminalInfoInteger(TERMINAL_MEMORY_USED)); ArrayResize(arr, 1, 1000000); Print("1: ", TerminalInfoInteger(TERMINAL_MEMORY_USED)); }
Before: 423 0: 423 1: 431
Am I understanding correctly that a highlighted line will not reduce the reserved memory?
void OnStart() { double arr[]; Print("Before: ", TerminalInfoInteger(TERMINAL_MEMORY_USED)); ArrayResize(arr, 1, 1000000); Print("1: ", TerminalInfoInteger(TERMINAL_MEMORY_USED)); ArrayResize(arr, 2, 500000); Print("2: ", TerminalInfoInteger(TERMINAL_MEMORY_USED)); ArrayFree(arr); Print("Free: ", TerminalInfoInteger(TERMINAL_MEMORY_USED)); }
Before: 423 1: 431 2: 431 Free: 424
Use MQLInfoInteger to get the memory used by the script directly instead terminal memory used.
MQLInfoInteger(MQL_MEMORY_USED)
I tested and it seems the reduction of reserve size does not reduce memory usage, it needs to be done with ArrayFree which deletes the data in the array.
void OnStart() { double arr[]; Print("Before: ", MQLInfoInteger(MQL_MEMORY_USED)); ArrayResize(arr, 1, 10000000); Print("1: ", MQLInfoInteger(MQL_MEMORY_USED)); ArrayFree(arr); ArrayResize(arr, 2, 500000); Print("2: ", MQLInfoInteger(MQL_MEMORY_USED)); ArrayFree(arr); Print("Free: ", MQLInfoInteger(MQL_MEMORY_USED)); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use