Memory: stack and heap
There are two pools of memory that are available to you as a C++ programmer: the stack and the heap. Until now, we’ve been using the stack. This video (9:30) explains the difference between the stack and the heap, and shows how to allocate and deallocate memory on the heap.
Resources
Comprehension check
- Ordinarily, space for variables in C++ is allocated on the ___________.
- Every function call gets its own _________________________ which includes parameters passed to the function, locally declared variables, and a return address.
- Memory leaks are caused by a failure to ______________________________ space on the heap when it is no longer needed.
- The amount of _______________________ memory is fixed.
- Data on the heap is accessed via _____________________________.
Answers: sɹǝʇuᴉod / ʞɔɐʇs / ǝʇɐɔollɐǝp / ǝɯɐɹɟ ʞɔɐʇs / dɐǝɥ
Amusement
Source: Shen Comix (with modifications by some anonymous programmer)
Copyright © 2023–2025 Clayton Cafiero
No generative AI was used in producing this material. This was written the old-fashioned way.