开发者

C++ stack overflow - visual studio 2008

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->l开发者_StackOverflow社区inker->system but it didn't worked! I'm working using 2GB Ram.How do i avoid stack over flow.


Stop using the stack! Use heap memory!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜