Stack allocation

See Stack .

Use a runtime stack to keep track of the operand stack , program counter (PC) and environment of functions.

Functions can be recursive. We can create a new instance of a function via stack frames for each recursive call.

The size of local variables such as arrays may depend on a parameter passed to the function, because the stack can grow as much as required.


  • Difficult to manipulate data structures. They are tied to the function invocations that created them.

    Recursive data structures such as list and trees cannot be handled naturally.

  • Only objects whose size is known at compile time can be returned as the result of a function, because the caller needs to reserve stack space for the return value.