Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the maximum index size in bytes can be declared in arrays?
Posted

In fact the limit is defined if the compiler is 32 bits or 64 bits...
In theory a 32 bit computer allows for 4gb, but you will never be able to allocate that much as the operating system has its own limit, memory is already in use by other programs and the operating system itself and an array uses a single block of memory. So, even if your computer still has free memory, it may be simple unable to allocate a 1gb memory (for example) if the memory is fragmented.

On 64 bits computers, the value is something like 4 billion times 4gb... I don't know what's the name for that, but then how much memory do the computer have?
 
Share this answer
 
Comments
lewax00 30-Oct-12 12:29pm    
The total is 16 exabytes (I don't think there is even a super computer today with that much RAM, but I might be wrong). This is assuming that each byte has an address, but addresses may just as easily be for words (which can differ my architecture) so you might reasonably expect as much as 128 exabytes (assuming each word was 8 bytes/64 bits). Of course both of these numbers are ridiculously high for today's computers, but maybe someday we'll utilize it fully.
The maximum depends on the computer. On a computer with 32GB memory, you can create bigger arrays then on a computer with 4GB memory.
 
Share this answer
 
v2
Comments
lewax00 30-Oct-12 12:17pm    
I'm not sure that's entirely true. The compiler also as to store the value, and it probably makes some assumptions about how large that value can be (for example, it seems unlikely that a 32-bit compiler would allow for array sizes greater than 2^32-1).
Thomas Daniels 30-Oct-12 12:18pm    
Ok, thanks! I'll update my answer.
It depends on the storage method.

When using arrays on the stack, the size is limited by the stack size of the application.

On the heap, the size is limited by the virtual memory.

For stack and heap, it is the actually available (free) memory when declaring or allocating.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900