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:
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.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?
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?
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,

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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