b: (1) Storage for
them exists only while the subroutine is active
(while it has not yet returned control to its caller).
(2) When it exists, the storage is on the run-time stack.
(1) Storage for them exists while the program is in
(2) Storage is in the data section of memory.
are three places in memory where data may be placed:
in the data section
.data in assembly language),
on the run-time stack,
and on the heap.
A subroutine other than
can have data in the
In high-level programming languages, such as "C",
this type of storage is called static.
Variables whose storage is allocated on the run-time stack are (sometimes) called automatic variables. This is because their storage is "automatically" pushed and popped as a subroutine is entered and exited. Usually the word "variable" means "automatic variable".
A variable whose memory is located in the heap is called
a dynamic variable.
Chapter 33 of these notes discusses the heap.
The heap is where memory for objects is found
new operation in Java or C++).
In "C" dynamic memory is allocated using the
operation (or similar).
The heap is on top of the data segment. As dynamic variables are created it grows upward (towards the stack)
(Review:) What happens if the stack and heap get larger and larger?