Are there any problems when using the stack instead of the heap?
Basically I want some 200 positions in memory (or more, 1000, who knows, this is hypothetical anyways), I can allocate it in the stack using an array, or on the heap using malloc()
. On the heap I have to remember to always free()
the memory...but using the stack, as soon as the function returns, all the memory is nicely cleaned for me.
I am just wondering if there are any issues with holding large amounts of memory on the stack. As far as I know, the stack and the heap are basically the same, just they sit on opposite sides in a RAM frame, and they grow towards the other, like in the image below.