c++ - 2D 数组 100x100 堆栈溢出;堆上没有错误。由 小码哥发布于

标签 c++ stack-overflow heap-memory stack-memory

我通过执行以下操作在堆栈上创建了一个二维数组:

    grid gridArray[100][100] = {{}};

但是,我遇到了堆栈溢出。

auto gridArray = new grid[100][100]();

如果我把它放在堆上,我不会收到错误。

我不太清楚这是为什么;堆栈无法分配与堆一样多的内存吗?我现在这样做有危险吗?

谢谢。

最佳答案

I don't exactly know why this is; is the stack unable to allocate as much memory as the heap?

就是这样。堆栈空间有限。根据经验,如果您有超过几 KB 的数据,则应该使用堆。

参见:What and where are the stack and heap?

关于c++ - 2D 数组 100x100 堆栈溢出;堆上没有错误。由 小码哥发布于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17349007/

相关文章:

c++ - 带有自定义 argc 和 argv 的 getopt_long() 函数

c++ - 如何使用宏 C++ 获取带有字符串的结构成员

android - 递归 + 900 个元素 + 邻居检查 = 导致 stackoverflow

c++ - 函数是否应该返回 "new"对象

java - 用于大图度量计算的 JVM 热点选项 :garbage collection

android - 通过 httpPost 将 base64 图像上传到服务器时出现问题

c++ - 单击“打印”按钮后,Qt 打印对话框重新出现

c++ - 使用 char 或 unsigned char 数组存储原始数据更好吗?

c++ - 这个递归程序的堆栈溢出错误? - C++

java - StackOverflowError 多次发生