14,137,520 members
See more:
What is the maximum index size in bytes can be declared in arrays?
Posted

## Solution 2

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

## Solution 1

The maximum depends on the computer. On a computer with 32GB memory, you can create bigger arrays then on a computer with 4GB memory.
v2
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.

## Solution 3

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.

Top Experts
Last 24hrsThis month
 OriginalGriff 150 Richard Deeming 115 phil.o 55 CPallini 50 Gerry Schmitz 48
 OriginalGriff 4,186 Richard MacCutchan 1,715 Patrice T 1,277 Gerry Schmitz 998 phil.o 953