What is the maximum size of static array, and dynamic array? I think that there is no limit for dynamic array but why static arrays have a limited size?
-
There is no range as such. Lot depend on your machine configuration. – Digital_Reality May 31 '14 at 11:46
-
@Digital_Reality I asked cause `int Data[8][499][15];` fails on my computer – Quest May 31 '14 at 11:48
-
that is just 29MB storage. I guess, there might be some other allocation causing this. – Digital_Reality May 31 '14 at 11:49
-
it also depends on compiler, some compilers might move that allocation to the heap from the stack. – Mgetz May 31 '14 at 11:53
-
When you say "fails on my computer", do you mean it fails to compile or does it crash? Is that a function-local variable? – bereal May 31 '14 at 12:03
-
@bereal it fails to compile, It is a class variable – Quest May 31 '14 at 12:11
-
1In your comment to shekhar's answer you mention that, on the contrary, it dumps. Which means that it compiles. Also, by "class variable", do you mean that it's a static member? – bereal May 31 '14 at 12:16
-
I guess that by "static" he means "non-static" – M.M May 31 '14 at 13:36
2 Answers
Unhandled exception at 0x011164A7 in StackOverflow.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00482000)
This looks more like a runtime error. More precisely - stack overflow.
In most places the size of array is limited only by available memory. However, the limit on stack allocated objects is usually much more severe. By default, it's 1Mb on Windows and 8Mb on Linux. It looks like your array and other data already on the stack is taking more space than the limit.
There are few ways to avoid this error:
- Make this array
static
or declare it at top level of your module. This way it will be allocated in.bss
segment instead of stack. - Use
malloc
/new
to explicitly allocate this array on heap. - Use C++ collections such as
std::vector
instead of arrays. - Increase stack size limit. On Linux this can be done with
ulimit -s unlimited

- 17,928
- 1
- 57
- 65
-
1gcc has a switch to increase stack size also. On my system it can go to over 1GB (default is 2MB). – M.M May 31 '14 at 13:35
The maximum size of an array is determined by the amount of memory that a program can access. On a 32-bit system, the maximum amount of memory that can be addressed by a pointer is 2^32 bytes which is 4 gigabytes. The actual limit may be less, depending on operating system implementation details.
Note that this has nothing to do with the amount of physical memory you have available. Even on a machine with substantially less than 1 GB of RAM, you can allocate a 2 GB array... it's just going to be slow, as most of the array will be in virtual memory, swapped out to disk.

- 18,735
- 7
- 49
- 73
-
I have struct(232 B) and allocated it this way `struct_name Data[8][499][15]; so why it fails durning compile time? – Quest May 31 '14 at 12:00
-
@Quest what compiler are you using and what error are you getting? – Piotr Praszmo May 31 '14 at 12:02
-
@Banthar that's all I can see: Unhandled exception at 0x011164A7 in StackOverflow.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00482000). VC++ 2013 – Quest May 31 '14 at 12:06
-
This all might be happening because your computer environment is not fit to perform this array allocation! – Am_I_Helpful May 31 '14 at 12:10