what the maximum size of an array allowed?

Started by
15 comments, last by menyo 12 years, 5 months ago
i know if you do

int[] = new int[100000] ;
thtats ok , but takes a lot of time to create these



i wish to just use

int[20000] , but its some were between 15000 and 20000 it give an error, is there a way to increase this amount to at least 50,000
Advertisement

i know if you do

int[] = new int[100000] ;
thtats ok , but takes a lot of time to create these



i wish to just use

int[20000] , but its some were between 15000 and 20000 it give an error, is there a way to increase this amount to at least 50,000


This might be language dependent, but in C#, because the size parameter is of type int, it can only be int.MaxValue.
What language? In C++, 20K is easily doable, even allocated on the stack.

What specifically is the error.

Frankly int[80000] is only like 1/3 a MB on a 32bit system.

int[] = new int[100000] ;
thtats ok , but takes a lot of time to create these

So don't do that.

Figure out what is slow about it. Is it the time taken to allocate the memory? Is it initialization? (Slow initialization is unlikely, but I suppose it is possible if you have a poor processor and are out of memory.) Consider using one of the container classes instead if it makes sense for your situation.


int[20000] , but its some were between 15000 and 20000 it give an error, is there a way to increase this amount to at least 50,000
[/quote]


What is your error, exactly?

I can allocate 500000 just fine on my machine, rather quickly.
Are you saying that if you make a large array without using [font="'Courier New"]new[/font], then it begins failing with large sizes?
If so, you're probably allocating your array on the stack, which is bad. Large objects should be allocated with [font="'Courier New"]new[/font] or [font="'Courier New"]malloc[/font].
If it's slow, have you tried to switch to release mode and to run it without the debugger?
Here are most default stack sizes.

You can generally increase the size of the stack, but its generally much better/easier to simply allocate on the heap ( aka, new ).
I was stupid.

Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.


blink.gif What?
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.


That makes no sense. It depends on what you use your array for. The hash table in a chess program is an array with a size of several gigabytes.

To the original question: If you have a hard time defining a large array, you are probably defining it as a local variable (i.e., on the stack). A global array or an array allocated on the heap will allow much larger sizes. If your program takes a long time in something as simple as allocating a smallish array, there's something that needs fixing. Post a short example program so we can see what you are doing. Also, let us know what platform, compiler and compiler settings you are using.

This topic is closed to new replies.

Advertisement