It is highly recommended that huge-sized variables should go to the heap via malloc
or new
. But, you can still have such big array in stack by increasing the stack size. This is often needed when you could have extremely deep recursion.
Linux/gcc has the 8MB of default size for stack, while Windows has 1MB. The stack size may be increased by tweaking linker options or binaries.
[EDITED] For example, you may increase the stack size in gcc:
gcc -Wl,--stack,16777216 hello.c
(This is only for MigW/cygwin gcc on Windows)
So, the stack will be 16MB.
Also, the stack size can be modified the command ulimit
by like (this is the easist way in Linux):
ulimit -s 16777216
Note that ulimit -s
will give you the current size of the stack.
Finally, you may call setrlimit
in your program.