Download MetaTrader 5

How large is the size of one-dimension array can be?

To add comments, please log in or register
Are you accustomed to using the standard library? MQL5 has one!
haoxiang xie
1076
haoxiang xie 2014.07.09 16:19 

I need a large size of array buffer to store testing data in my ea.such as the code below:

 

double Buff[size];

double BuffDym[];

ArrayResize(BuffDym,size);

 

 when the value of size is to large,the compiler will come out a error said :array is too large.

I want to know the largest value of size that I can used. 

Alain Verleyen
Moderator
30744
Alain Verleyen 2014.07.09 16:37  
xhxiang:

I need a large size of array buffer to store testing data in my ea.such as the code below:

 

 

 when the value of size is to large,the compiler will come out a error said :array is too large.

I want to know the largest value of size that I can used. 

What the documentation says ?
haoxiang xie
1076
haoxiang xie 2014.07.10 05:06  
angevoyageur:
What the documentation says ?

Total amount of elements in the array cannot exceed 2147483647. 

 I found this in the Docs about ArrayResize(). 

 If you try this scripts below:

 

void OnStart()
  {
//---
   int size=2000000000; // < 2147483647
   double a[];
   double b[];
   datetime c[];
   ulong d[];

   if(ArrayResize(a,size)==-1 || 
      ArrayResize(b,size)== -1 ||
      ArrayResize(c,size)== -1 ||
      ArrayResize(d,size)== -1)
      Print("resize error");
   else
      Print("ok");
      
   

  }

 

you will away get "resize error".  and if you declare a static array:

 

double a[2000000000];
double b[2000000000];
datetime c[2000000000];
ulong d[2000000000];

the compiler get error: array is too large 

Alain Verleyen
Moderator
30744
Alain Verleyen 2014.07.10 13:34  
xhxiang:

Total amount of elements in the array cannot exceed 2147483647. 

 I found this in the Docs about ArrayResize(). 

 If you try this scripts below:

 

 

you will away get "resize error".  and if you declare a static array:

 

the compiler get error: array is too large 

Of course you need to have sufficient memory to allocate such size to your arrays.

A double is 8 bytes x 2,000,000,000 = around 16 Gb only for 1 array.

haoxiang xie
1076
haoxiang xie 2014.07.10 14:01  
angevoyageur:

Of course you need to have sufficient memory to allocate such size to your arrays.

A double is 8 bytes x 2,000,000,000 = around 16 Gb only for 1 array.

Is there a way to get as much as I can ? I mean some algorithm to calculate how much memory I can allocate...
To add comments, please log in or register