Pergunta

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.

Foi útil?

Solução

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.

See: What and where are the stack and heap?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top