For the purposes of this course, we can break the memory into three areas.
The static area of memory is of fixed size. Part of it holds
things that do not change while the program runs, including:
A second part of the static area holds global variables, which can be changed by the programs, but that always occupy a fixed number of bytes. The area is called static because its size does not change while the program runs.
|The run-time stack holds frames, where each frame holds information about one function call, including the function's variables, information about which function called it, and some information to help the program manage the run-time stack. The run-time stack grows and shrinks as the program runs. When a function is called, a frame is created for it in the run-time stack. When a function returns, its frame is removed.|
When a function returns, its entire frame, including all of
its local variables, is removed. So the memory occupied
by the local variables cannot be used after the function returns.
The heap is another area of memory that can grow and shrink, but where you have direct control over when memory is allocated and when it is deallocated. The next page explains how to allocate and deallocate memory in the heap.
What is stored in the static area of memory? Answer
What is stored in the run-time stack? Answer
How is memory allocation and deallocation managed in the run-time stack? Answer
What is the heap for? Answer
How is memory allocated and deallocated in the heap? Answer