How to find out the reserved memory of a dynamic array?

 
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?
 
Vladislav Boyko:
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 ?
 
Alain Verleyen #:
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);
  }
 

My English is weak, sorry.

Vladislav Boyko #:
But there are doubts if the reserve size is calculated at runtime.

But I have doubts in the case when the reserve size will be calculated at runtime.

Vladislav Boyko #:
Usually the reserve size is known at compile time (does not change at runtime).

By reserve size I mean the value that is passed to the third parameter of ArrayResize

 

Looks like I found a way to find out (not very convenient).

Vladislav Boyko #:
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
Vladislav Boyko #:
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
 
Vladislav Boyko #:

Looks like I found a way to find out (not very convenient).

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));
  }
 
Laszlo Tormasi #:
Use MQLInfoInteger to get the memory used by the script directly instead terminal memory used.

I got it, thank you very much!

Reason: