Click here to Skip to main content
14,137,520 members
Rate this:
Please Sign up or sign in to vote.
See more:
What is the maximum index size in bytes can be declared in arrays?
Rate this: bad
Please Sign up or sign in to vote.

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.
Rate this: bad
Please Sign up or sign in to vote.

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.
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.
Rate this: bad
Please Sign up or sign in to vote.

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190518.1 | Last Updated 30 Oct 2012
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100