Sign in to follow this  

what the maximum size of an array allowed?

This topic is 2229 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
[quote name='thedodgeruk' timestamp='1319583251' post='4876958']
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
[/quote]

This might be language dependent, but in C#, because the size parameter is of type int, it can only be int.MaxValue.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='thedodgeruk' timestamp='1319583251' post='4876958']
int[] = new int[100000] ;
thtats ok , but takes a lot of time to create these
[/quote]
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.

[quote]
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.

Share this post


Link to post
Share on other sites
Are you saying that if you make a large array [i]without[/i] using [font="'Courier New"]new[/font], then it begins failing with large sizes?
If so, you're probably allocating your array on the [url="http://en.wikipedia.org/wiki/Call_stack"]stack[/url], which is bad. Large objects should be allocated with [font="'Courier New"]new[/font] or [font="'Courier New"]malloc[/font].

Share this post


Link to post
Share on other sites
[url="http://www.cs.nyu.edu/exact/core/doc/stackOverflow.txt"]Here are most default stack sizes.[/url]

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

Share this post


Link to post
Share on other sites
[quote name='weka' timestamp='1319683180' post='4877440']
Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.
[/quote]

[img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img] What?

Share this post


Link to post
Share on other sites
[quote name='weka' timestamp='1319683180' post='4877440']
Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.
[/quote]

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.

Share this post


Link to post
Share on other sites
[quote name='Cornstalks' timestamp='1319684388' post='4877443']
[quote name='weka' timestamp='1319683180' post='4877440']
Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.
[/quote]

[img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img] What?
[/quote]

Oh, I am sorry. I read that wrong. I thought the NUMBER of arrays.. not the size. My apologies.

Share this post


Link to post
Share on other sites
[quote name='weka' timestamp='1319859875' post='4878111']
[quote name='Cornstalks' timestamp='1319684388' post='4877443']
[quote name='weka' timestamp='1319683180' post='4877440']
Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.
[/quote]

[img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img] What?
[/quote]

Oh, I am sorry. I read that wrong. I thought the NUMBER of arrays.. not the size. My apologies.
[/quote]

I don't think thats making any more sense....

Share this post


Link to post
Share on other sites
[quote name='menyo' timestamp='1320005535' post='4878672']
[quote name='weka' timestamp='1319859875' post='4878111']
[quote name='Cornstalks' timestamp='1319684388' post='4877443']
[quote name='weka' timestamp='1319683180' post='4877440']
Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.
[/quote]

[img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img] What?
[/quote]

Oh, I am sorry. I read that wrong. I thought the NUMBER of arrays.. not the size. My apologies.
[/quote]

I don't think thats making any more sense....
[/quote]
Have you ever seen anyone seen more than 1000 sets in an array? test[1000]

Share this post


Link to post
Share on other sites
[quote name='weka' timestamp='1320009272' post='4878687']
[quote name='menyo' timestamp='1320005535' post='4878672']
[quote name='weka' timestamp='1319859875' post='4878111']
[quote name='Cornstalks' timestamp='1319684388' post='4877443']
[quote name='weka' timestamp='1319683180' post='4877440']
Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.
[/quote]

[img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img] What?
[/quote]

Oh, I am sorry. I read that wrong. I thought the NUMBER of arrays.. not the size. My apologies.
[/quote]

I don't think thats making any more sense....
[/quote]
Have you ever seen anyone seen more than 1000 sets in an array? test[1000]
[/quote]

Yeah. Have you? What about loading a file into memory? Even if it's only a few kilobytes, it's still a few thousand characters. It's really easy (and not rare at all) to have arrays with lengths more than 1000.

And at any given point in time, applications will often have lots of different arrays. Depending on the application, there can be hundreds of arrays used, each with thousands of elements.

I assume by "sets" you actually mean "elements".

Share this post


Link to post
Share on other sites
[quote name='Cornstalks' timestamp='1320010984' post='4878695']
[quote name='weka' timestamp='1320009272' post='4878687']
[quote name='menyo' timestamp='1320005535' post='4878672']
[quote name='weka' timestamp='1319859875' post='4878111']
[quote name='Cornstalks' timestamp='1319684388' post='4877443']
[quote name='weka' timestamp='1319683180' post='4877440']
Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.
[/quote]

[img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img] What?
[/quote]

Oh, I am sorry. I read that wrong. I thought the NUMBER of arrays.. not the size. My apologies.
[/quote]

I don't think thats making any more sense....
[/quote]
Have you ever seen anyone seen more than 1000 sets in an array? test[1000]
[/quote]
I assume by "sets" you actually mean "elements".
[/quote]
Yes, elements.


Share this post


Link to post
Share on other sites
[quote name='weka' timestamp='1320009272' post='4878687']
[quote name='menyo' timestamp='1320005535' post='4878672']
[quote name='weka' timestamp='1319859875' post='4878111']
[quote name='Cornstalks' timestamp='1319684388' post='4877443']
[quote name='weka' timestamp='1319683180' post='4877440']
Honestly, don't even worry about it. The most people use per array, on average, is probably less than five hundred.
[/quote]

[img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img] What?
[/quote]

Oh, I am sorry. I read that wrong. I thought the NUMBER of arrays.. not the size. My apologies.
[/quote]

I don't think thats making any more sense....
[/quote]
Have you ever seen anyone seen more than 1000 sets in an array? test[1000]


[/quote]

I'm doing [2048*2048] right now....
And need multiple arrays or need to stuff a single one with big structs which would be inneficient for the project i'm currently on.

Share this post


Link to post
Share on other sites

This topic is 2229 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this