今天我面临一个奇怪的问题。 当我尝试为char数组分配10M字节时,当我尝试执行代码时,我会收到堆栈溢出错误。 对这个问题有什么想法吗? 谢谢。
岳
Today I face a strange problem. When I try to allocate 10M bytes for a char array, I'll receive a stack overflow error when I try to execute the code. Any idea for the problem? Thanks.
Yue
最满意答案
使用什么语言? 假设使用C / C ++,并且如果在堆栈上分配数组,例如
char A[10000000];在函数或块作用域内,您可能正在达到线程的堆栈限制。 在VS属性 - 配置属性 - 链接器 - 系统 - 堆栈保留大小中使用此设置
并重新链接。
对于这样的大小,最好使用动态分配
char * A = new char [10000000];
或者在C中使用malloc()。
使用这两个,您将在堆区域上进行分配,而不是在堆栈上进行分配。
What language are using? Assuming C/C++, and if you allocate your array on the stack, for e.g.
char A[10000000];inside a function or block scope, you may be hitting the stack limit of the thread. Play with this setting in VS Properties - Configuration Properties - Linker - System - Stack Reserve Size
and relink.
It's better to use dynamic allocation for such a size, with
char* A = new char[10000000];
or use malloc() in C.
With these two, you are allocation on the heap area, not on the stack.
更多推荐
发布评论