简体   繁体   English

C ++堆栈溢出-Visual Studio 2008

[英]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! 我声明并初始化了一个具有[100] [1000] [1000]个char元素(100MB)的数组,但第一次并没有说到堆栈溢出。但是当我在一段时间后运行它时,它抛出了堆栈溢出异常! I increased the -Stack Reserve Size- to 200,000,000 in project options->linker->system but it didn't worked! 我在项目选项->链接器->系统中将-Stack Reserve Size-增加到200,000,000,但没有成功! I'm working using 2GB Ram.How do i avoid stack over flow. 我正在使用2GB Ram。如何避免堆栈溢出。

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. 在Windows上,可以在调用CreateThread时对其进行控制。 There are pthread attr mechanisms for doing this on Unix too. 在Unix上也有pthread attr机制可以做到这一点。

In non-threaded code, on Unix there are ulimit settings that control this, but they can be restricted by platform limits. 在非线程代码中,在Unix上,有ulimit设置可以控制此设置,但可以受平台限制的限制。 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). 例如,在AIX中的32位进程中,堆栈和堆在第二段中一起增长,因此两者的最大容量为256Mb(一旦命中,就会充满乐趣)。

There may be platform mechanisms that you can use to control this (like ulimit), but the suggestion to use the heap is likely prudent. 可能有一些平台机制可用于控制此机制(例如ulimit),但是使用堆的建议可能是谨慎的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM