Heap Dynamic:
In programming, heap refers to a common pool of memory that is available to the program. The
management of the heap is either done by the applications themselves, allocating and
deallocating memory as required, or by the operating system or other system program.
Explicit Heap-Dynamic Storage Binding:
Explicit Heap-Dynamic variables are nameless (abstract) memory cells that are allocated and
deallocated by explicit run-time instructions specified by the programmer.
• Allocated and deallocated by explicit directives, specified by the programmer, which take
effect during execution
• Referenced only through pointers or references, e.g. dynamic objects in C++ (via new
and delete), all objects in Java, malloc and free in C
int *intnode; //c or c++
intnode = new int;
. . .
delete intnode;
Example in C++:
int* intnode;
...
intnode = new int; // allocates an int cell
...
delete intnode; // deallocates the cell to which intnode
points
The new operator automatically creates an object of proper size, and remains a pointer of the
connect type. To free the space for this object, use the delete operator. (With explicit heap
dynamic variables we do not need to incur the overhead of garbage collection).
Disadvantages:
1. Failure to deallocate storage results in memory leaks
2. Other difficulties in using variables correctly (dangling pointers, aliasing)
3. Heap fragmentation
On page 229 of Data Structures with C++ using STL, second edition, by William Ford &
William Topp:
You can think of the heap as a bank of memory, much like a financial bank that
maintains a reserve of money. A program can borrow (allocate) memory from the
heap when additional storage space is required and then pay it back (deallocate)
when it is no longer needed.