Quick question, I know this is actually sorta a stupid question but what is the maximum number of elements in a array?

Not one time has anyone told me a real answer. They all seem to sorta let that question slide by. Also have tired a google search and found nothing related to that.

No it may not simply be a simple number, could is be constrainted to RAM? Just wondering if anyone knows.

I couldn't really find anything on it, either. I'm guessing that it really depends on the system. You could probably create as many elements as you could the largest integer on a system would be, considering how that could differ for different platforms, ie, 64 Bit vs 32 bit.

But before that, you'd probably reach the upper limit of memory. Keep in mind that every time you place an object in an array, it allocates a certain amount of memory to that object. So, if an object of type int is 32 bits long, that's how much memory that would be allocated for each element in the array. So, if an array consisted of 500 int objects, then it would be right at around 2KB in size.

Hi,

It is limited with your Virtual Memory Size (if you set to automatic management then it is limited to your free disk space on the drive where your page file resides) I successfully created an array of 100,000,000 int's and the Task manager showed me ~400MB of Virtual Mem usage (I have 512 RAM+512 non-resizable page file) when I created 250,000,000 I got an OS warning saying Virtual Memory too low and for 1,000,000,000 elements the code just gave an Out of Memory error and breaked to IDE.

Loren Soth

Wow, one billion element array. Well thanks for both of your replies!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.