简体   繁体   English

二维数组 100x100 堆栈溢出; 堆上没有错误。 C++

[英]2D array 100x100 stack overflow; no error on heap. c++

I've made a 2D array on the stack by doing:我通过执行以下操作在堆栈上创建了一个二维数组:

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

However, I get a stack overflow.但是,我得到了堆栈溢出。

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

If i put it on the heap, I don't get an error.如果我把它放在堆上,我不会收到错误。

I don't exactly know why this is;我不完全知道这是为什么; is the stack unable to allocate as much memory as the heap?堆栈无法分配与堆一样多的内存吗? Is there any danger in the way I'm doing it now?我现在这样做有什么危险吗?

Thanks.谢谢。

I don't exactly know why this is;我不完全知道这是为什么; is the stack unable to allocate as much memory as the heap?堆栈无法分配与堆一样多的内存吗?

That's exactly it.就是这样。 Stack space is limited.堆栈空间有限。 As a rule of thumb, if you have more than a few KB of data you should use the heap.根据经验,如果您有超过几 KB 的数据,您应该使用堆。

See: What and where are the stack and heap?请参阅: 堆栈和堆是什么以及在哪里?

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

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