Professional Documents
Culture Documents
ID:17701095
static: global variable storage, permanent for the entire run of the program.
heap: dynamic storage (large pool of memory, not allocated in contiguous order).
STATIC MEMORY
Static memory persists throughout the entire life of the program, and is usually used to
store things like global variables, or variables created with the static clause.
STACK MEMORY
The stack is used to store variables used on the inside of a function (including
the main() function). It’s a LIFO, “Last-In,-First-Out”, structure.
1. Heap : Heap allocations (dynamically allocated memory) is useful when you want
to be more flexible than the above. Frequently, a function gets called to respond
to an event (the user clicks the "create box" button). The proper response may
require allocating a new object (a new Box object) that should stick around long
after the function is exited, so it can't be on the stack. But you don't know how
many boxes you would want at the start of the program, so it can't be a static.
2. Stack : Stacks usually start high and grow down to lower addresses. You run out
of memory when the stack meets the dynamic allocator somewhere in the middle
(but refer to physical versus virtual memory and fragmentation). Multiple threads
will require multiple stacks (the process generally reserves a minimum size for
the stack).
RunTime Optimization:
C++ run-time support routines obviously have a significant cost, because otherwise
such behavior would have be inlined. Here techniques are presented to avoid the
language features that cause an implicit call to costly run-time support routines.