A stack is a fast memory region where values are placed one after another and released in last-in, first-out order. When a function finishes, its most recently added values are removed first. section 2.1
The core rules are simple:
- The stack works well for values whose exact size is known at compile time, such as an i32, which always occupies 4 bytes. section 2.1
- Values are removed from the top first, much like dishes being taken from a stack. section 2.1
- When data has an unknown size, the data can live on the heap while a fixed-size pointer to it remains on the stack. section 2.1
- Small embedded devices may provide only stack memory because they have no operating system to request heap memory. section 2.1
A dish stack in memory
Imagine placing a variable on top of the previous variable. When the function ends, the newest variable comes off first, then the one beneath it. This arrangement is fast because the values sit next to one another and their sizes are known. section 2.1













