0

Stack flow

Hi We all know that function code goes into code section of memory. Also memory which is not allocated by new operator goes into stack. So, does this mean that during programme run, we are indirectly allocating memory on stack also ?

31st May 2020, 7:03 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Respostas
+ 3
Yes this is called static memory allocation. Dynamic and Static both jobs are done by the compiler. Also access to static memory is very fast.
31st May 2020, 7:58 PM
Robin Singh
Robin Singh - avatar
+ 3
We know how much stack space a function will need, at compile time, so it's not really the same kind of allocation like with heap space. There is a max stack size and you can fit many "stack frames" in there, but if your stack frames are very large or you recurse very deeply then you will run into overflow and there is no resizing the stack like an std::vector.
31st May 2020, 9:32 PM
Schindlabua
Schindlabua - avatar
+ 2
yes, which is why the term “stack overflow” exists.
31st May 2020, 7:50 PM
Bobby Fischer
Bobby Fischer - avatar