URGENT: What is the maximum size an array can have in MQL5?

 

I need to know the maximum size of an array in MQL5. I searched this forum but didn't find the answer.. if anybody knows i'll appreciate the info.

Thnx

 

See Numerical Type Constants

INT_MAX

Maximal value, which can be represented by int type

2147483647


 
Thanks Rosh...

 
Rosh, (or anybody) why is this code giving me an out of range error:
class CMemory
   {
protected:
   int            my_buffer[];
public:
   void           CMemory()      { return; } 
   void          ~CMemory()      { ArrayFree(my_buffer); }
   virtual void   Init(int size) { if (size <= INT_MAX) ArrayResize(my_buffer,size,0); ArrayInitialize(my_buffer,0);}

   int            Read(ulong address){ return( my_buffer[address] ); }
   void           Write(ulong address, int value){my_buffer[address] = value;}
   };
   
void OnStart()
  {
   CMemory Pattern;
   Pattern.Init(INT_MAX);
   Pattern.Write(2147483646,43);
   Print("Pattern# 2147483646 value is: ",Pattern.Read(2147483646));
  }
I tried creating an array that size outside a class and it works, Why doesn't work inside a class?
Rosh:

See Numerical Type Constants

INT_MAX

Maximal value, which can be represented by int type

2147483647



 
nanobot:
Rosh, (or anybody) why is this code giving me an out of range error:I tried creating an array that size outside a class and it works, Why doesn't work inside a class?

Thank you for message.

The reason is that you try to allocate array more then 2Gb of size.

If you check GetLastError() value you will get error code 4011. Function ArrayResize must return -1 if resizing finishes with error, but it doesn't.
 
nanobot:
Rosh, (or anybody) why is this code giving me an out of range error:I tried creating an array that size outside a class and it works, Why doesn't work inside a class?

ArrayResize(my_buffer,size,0)

 ??  maybe large than the memory of your computer, 

 
nanobot:
Rosh, (or anybody) why is this code giving me an out of range error:I tried creating an array that size outside a class and it works, Why doesn't work inside a class?

Check if you get ERR_ARRAY_BAD_SIZE, it is related exactly to what alexvd suggests (arraysize >2GB).
 


In 32 bit systems the amount of memory, occupied by an application, can't exceed 2 Gb.

In 64 bit systems when Client Terminal allocates more than 256 MB of memory, it checks that required amount of physical memory is available.