VS 2012无法为10,000,000大小的char数组分配内存(VS 2012 can't allocate memory for 10,000,000 size char array)

编程入门 行业动态 更新时间:2024-10-22 17:21:59
VS 2012无法为10,000,000大小的char数组分配内存(VS 2012 can't allocate memory for 10,000,000 size char array)

今天我面临一个奇怪的问题。 当我尝试为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.

更多推荐

本文发布于:2023-08-03 13:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391376.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   分配   大小   内存   char

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!