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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.