Memory Lab
Five simulations of what happens in memory when your code runs: what an assignment copies, where frames and objects live, why contiguous storage is friendly to caches, what a growing buffer does to pointers into it, and when memory and resources are actually released. Each one follows the rules of the language you pick, and each comes with a tested program in C#, Python, Java and C++.
Addresses are small teaching numbers and the cache is a simplified model. They explain the mechanism; they are not measurements of any machine.
Simulation 1
Values and referencesAssignment copies either the data or only a reference to it. Watch a copy stay independent while an alias sees every change.
- values and references
- pointers
- copying
Lesson: Values, references and pointers
Simulation 2
Stack frames and heap objectsEach call pushes a frame for its parameters and locals; objects live on the heap until nothing refers to them. Overflow the teaching stack to see what each runtime does.
- stack and heap
- call stack
- overflow
- allocation
Lesson: The call stack and the heap
Simulation 3
Contiguous array vs linked nodesThe same values traversed as an array and as a linked list, with teaching addresses and a simplified cache-line model that counts line loads.
- addresses
- contiguous storage
- cache locality
- fragmentation
Simulation 4
Reallocation and invalidated referencesA dynamic array outgrows its buffer and moves. See what happens to a pointer, span, iterator or memoryview that pointed into the old one.
- allocation
- copying
- pointers
- addresses
Simulation 5
Reachability, garbage collection and RAIIMark everything the roots can reach, sweep the rest, and compare with cleanup that happens at a known point: using, try-with-resources, with and destructors.
- GC and RAII
- allocation
Where each M02 topic shows up
The Memory Lab is the interactive half of module M02, Memory Model. Fragmentation appears as the free gaps between scattered list nodes and the hole a freed buffer leaves; there is no allocator simulation.
- stack and heap
- Stack frames and heap objects
- values and references
- Values and references
- contiguous storage
- Contiguous array vs linked nodes
- allocation
- Stack frames and heap objects, Reallocation and invalidated references, Reachability, garbage collection and RAII
- GC and RAII
- Reachability, garbage collection and RAII
- cache locality
- Contiguous array vs linked nodes
- fragmentation
- Contiguous array vs linked nodes
- call stack
- Stack frames and heap objects
- overflow
- Stack frames and heap objects