Sign in to follow this  
Winegums

Array size limit?

Recommended Posts

Hi, this seems like such a silly problem, but I'm at a loss to figure out the cause. in C++, trying to make a big array... const double tempsize = 64*64*64; double arr[tempsize]; Is there a limit on the number of elements an array can have? Is there a way around this?

Share this post


Link to post
Share on other sites
If you try to allocate an array on the stack, then your array size is limited by the remain stack space. Depending on your operating system and compiler you may be able to increase the default stack space. However, you should consider allocating your array on the heap.

Share this post


Link to post
Share on other sites
Local arrays are limited to how much space is on the stack, which isn't very much. I think in Visual Studio, the default stack size is 2MB or something like that. So, large arrays should be allocated on the heap. There, your limit is determined by how much memory you have available and how fragmented it is.

Share this post


Link to post
Share on other sites
If you're using double on a platform where double is 8 bytes you really shouldn't try to use an array that large on the stack.
Your array would be 2MiB in size which is over the default stacksize(1MiB) in windows.

Thus if you want to use arrays that large you have to either allocate them on the heap or increase the stack size (You can do that by changing the linker settings, 32MiB/Thread is max in Windows)

Share this post


Link to post
Share on other sites

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