我通过执行以下操作在堆栈上创建了一个二维数组:
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 的数据,则应该使用堆。
关于c++ - 2D 数组 100x100 堆栈溢出;堆上没有错误。由 小码哥发布于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17349007/