Search code examples
c++heap-memorystack-memory

Using whole stack memory


Hello I heard that in c++ stack memory is being used for "normal" variables. How do I make stack full? I tried to use ton of arrays but it didnt help. How big is stack and where is it located?


Solution

  • Hello I heard that in c++ stack memory is being used for "normal" variables.

    Local (automatic) variables declared in a function or main are allocated memory mostly on stack (or register) and are deallocated when the execution is done.

    How do I make stack full? I tried to use ton of arrays but it didnt help.

    Using ton of arrays, many recursive calls, parameter passing large structs that contain ton of arrays are ways. Another way might also be to reduce stack size: -Wl,--stack,number (for gcc)

    How big is stack and where is it located?

    It depends on platform, operating system so on. Standard does not determine any stack size. Its location is determined by OS before the program starts. OS allocates a memory for stack from virtual memory.