A stack is a memory region that supports function execution by storing call state, registers, return information, and local data. Unlike the heap, it is usually managed implicitly by the operating system and compiler-generated code. section 7.4.3
A function call creates a stack frame for local variables and saved execution state; returning from the function deallocates that frame. A special stack register tracks the top, and the stack typically grows toward lower virtual addresses. section 7.4.3
Use the stack with these operational expectations:
- Treat insertion and deletion as constant-time operations because elements are handled at the stack boundary rather than at arbitrary positions. section 7.2
- Do not choose it for searching: stack search remains linear-time. section 7.2
- Expect stack memory to grow dynamically as execution uses more of it; the operating system commonly allocates needed memory lazily. section 7.4.3
Function execution
When one function calls another, the stack can preserve registers and other call state, record where execution returns, and provide a frame for the called function's local variables. Returning removes that frame. section 7.4.3
Figure 7.4 A process’s virtual memory address space consists of sections that serve different purposes. The text, data, and BSS sections are initialized at program startup, whereas the heap, memory-mapped region, and stack sections change dynamically at runtime (denoted with dotted lines).
Compare the stack with the heap and other process-memory sections, including which regions change dynamically during runtime. section 7.4.3













