Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In C++ the stack memory is where local variables get stored/constructed. The stack is also used to hold parameters passed to functions. </p> <p>The stack is like a very like the std::stack class, you push parameters onto it and then call a function. The function then knows the parameters it expects can be found on the end of the stack. Likewise the function can push locals onto the stack and pop them off it before returning from the function. (caveat- compiler optimizations and calling conventions all mean things aren't this simple)</p> <p>The stack is really best understood from a low level and I'd recommend this link <a href="http://www.creative.net.au/mirrors/asm/CH11/CH11-4.html#HEADING4-1">Art of Assembly - Passing Parameters on the Stack</a>. Rarely if ever would you consider any sort of manual stack manipulation from C++.</p> <p>Generally speaking the stack is preferred as it is usually in the CPU cache, so operations involving objects stored on it tend to be faster. However the stack is a limited resource, and shouldn't be used for anything large. Running out of stack memory is called a <a href="http://en.wikipedia.org/wiki/Stack_buffer_overflow">Stack buffer overflow</a>. It's a serious thing to encounter, but you really shouldn't come across one unless you have a crazy recursive function or something similar.</p> <p>Heap memory is much as rskar says. Generally speaking in C++ objects allocated with new, or blocks of memory allocated with the likes of malloc ends up on the heap. Heap memory almost always must be manually freed, though you should reallly use a smart pointer class or similar to avoid needing to remember to do so. Running out of heap memory can (will?) result in a std::bad_alloc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload