Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In C/C++: Local variables are allocated on the current stack frame (belonging to the current function). If you statically allocate an object, the whole object is allocated on the stack, including all of its member variables. When using recursion, with each function call a new stack frame is created, and all local variables are allocated on the stack. The stack has usually fixed size which and this value is usually written in the executable binary header during compilation/linking. However this is very OS and platform specific, some OS may grow the stack dynamically when needed. Because the size of the stack is usually limited, you can run out of stack when you use deep recursion or sometimes even when without recursion when you statically allocate large objects.</p> <p>The heap is usually taken as an unlimited space (only limited by the available physical/virtual memory), and you can allocate objects on the heap using malloc/new (and other heap-allocating functions). When an object is created on the heap, all of its member variables are created within it. You should see an object as a continuous area of memory (this area contains member variables and a pointer to a virtual method table), no matter where is it allocated.</p> <p>Literals, constants and other "fixed" stuff is usually compiled/linked into the binary as another segment, so it's not really is the code segment. Usually you can't alloc or free anything from this segment at runtime. However this is also platform specific, it might work differently on different platforms (for example iOS Obj-C code has a lot of constant references inserted directly into the code segment, between functions).</p>
 

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