views:

327

answers:

3

I declared and initialized an array having [100][1000][1000] char elements(100MB), it didn't say about a stack overflow at the first time.But when I running it after a while it throws a Stack overflow exception! I increased the -Stack Reserve Size- to 200,000,000 in project options->linker->system but it didn't worked! I'm working using 2GB Ram.How do i avoid stack over flow.

+8  A: 

Stop using the stack! Use heap memory!

jldupont
Agreed. 100MB on the stack is pretty absurd. And I thought I was bad for using more than a page...
asveikau
Use "Free Store" rather than using Heap
Prasoon Saurav
+1  A: 

Is there a reason you need to allocate that much stack memory? This is likely a deficiency in your algorithm - not a deficiency with the compiler.

Charlie Salts
A: 

Default stack size isn't a linker option, but is controlled via a number of esoteric platform specific mechanisms.

On windows, this can be controlled when you call CreateThread. There are pthread attr mechanisms for doing this on Unix too.

In non-threaded code, on Unix there are ulimit settings that control this, but they can be restricted by platform limits. For example, on AIX in 32-bit processes stack and heap grow together in the second segment, so you have a max of 256Mb for both (and lots of fun once they hit).

There may be platform mechanisms that you can use to control this (like ulimit), but the suggestion to use the heap is likely prudent.

Peeter Joot