Compare one value to 100 element array? - page 3

 
DonFx:

BTW (little bit off topic), is there any size limitation for arrays? This code prints out 0.

You're trying to allocate more than the 2GB limit for a 32-bit application.
 
JC:
You're trying to allocate more than the 2GB limit for a 32-bit application.

I would never have found it out. Thanks!

Have you any idea how is it possible to check it within the program to avoid errors?

(Any other way than if(arraysize(array)!=0) ...)

 
DonFx:

I would never have found it out. Thanks!

Have you any idea how is it possible to check it within the program to avoid errors?

(Any other way than if(arraysize(array)!=0) ...)

ArrayResize() returns -1 if it fails. The amount of memory you can allocate is going to depend not only on the amount of free memory on the computer, capped by the 2GB limit for 32-bit applications, but also, within free memory, by the largest contiguous block which Windows is able to allocate. That, in turn, is going to depend on the details of exactly how MT4 goes about requesting the memory from Windows.

Fundamentally, you're never going to get anywhere close to creating an array with a billion (1,234,567,890) entries.

 
JC:

ArrayResize() returns -1 if it fails. The amount of memory you can allocate is going to depend not only on the amount of free memory on the computer, capped by the 2GB limit for 32-bit applications, but also, within free memory, by the largest contiguous block which Windows is able to allocate. That, in turn, is going to depend on the details of exactly how MT4 goes about requesting the memory from Windows.

Fundamentally, you're never going to get anywhere close to creating an array with a billion (1,234,567,890) entries.

Thank you. "Fundamentally, you're never going to get anywhere close to creating an array with a billion (1,234,567,890) entries." You never know ... :)))
 
   int Val=1,234,567,890;

Of course it does.

  1. Max int is 2,147,483,647 so Val is fine, but maximum RAM is 3 GB on the 32 bit version. So 3GB/ (8bytes/int) = 402,653,184 is your theoretical max int array. Half that for a double array.
  2. Check your return codes and you would know why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles Probably:

    4025

    ERR_OUT_OF_MEMORY

    Out of memory



 
whroeder1:

but maximum RAM is 3 GB on the 32 bit version

(This is pedantic even by my standards, but I think we're both wrong. The default for a 32-bit app is 2GB. But, after checking, it turns out that MT4 is compiled with /LARGEADDRESSAWARE, giving it access to the full 4GB of address space, not 3GB. https://stackoverflow.com/questions/5185406/how-does-the-large-address-aware-flag-work-for-32-bit-applications-on-64-bit-com#answer-5185514)
Reason: