Array resize for object of a struct type

 

Hi all

I've a method which i call x-times. I fill an array in this method and I don't know how many times the method will be called during the runtime (every call of the method creates a new entry in the array. It could be upto 300 times before I "free" the array).

Short: I don't know the needed size of the array before runtime.

I used the function ArrayResize which works quite well if I have an int arr[] (or another simple datatype). Now, I have a "structure-array" and it doen't works with that function. There is no error but also no sucessfull resizing. I've simplified my code to test that (in "OnTimer" only for testing).

 

void OnTimer()
  {
  
  struct val_struc
  {
      string val1;
      string val2;
  };
  
  static val_struc MyArray[3];

  static int arrcount = 0;


  MyArray[arrcount].val1 = "TEST";
  MyArray[arrcount].val2 = "Test2";
  
  arrcount = arrcount + 1;
    
  ArrayResize(MyArray, 5, 0);
  
} 

ArrayResize function has no effect. Can anybody help me?

Thanks

Documentation on MQL5: Array Functions / ArrayResize
Documentation on MQL5: Array Functions / ArrayResize
  • www.mql5.com
Array Functions / ArrayResize - Documentation on MQL5
 
fx_ta:

Hi all

I've a method which i call x-times. I fill an array in this method and I don't know how many times the method will be called during the runtime (every call of the method creates a new entry in the array. It could be upto 300 times before I "free" the array).

Short: I don't know the needed size of the array before runtime.

I used the function ArrayResize which works quite well if I have an int arr[] (or another simple datatype). Now, I have a "structure-array" and it doen't works with that function. There is no error but also no sucessfull resizing. I've simplified my code to test that (in "OnTimer" only for testing).

 

ArrayResize function has no effect. Can anybody help me?

Thanks

 

Why don't you click that (ArrayResize function). it says " Note The function can be applied only to dynamic arrays. ... ", and you have static one.

And beside, if you "... don't know the needed size of the array before runtime.", don't you think it's better to use dynamic arrays, no ?