The heap is a region of memory for data whose size is not known at compile time or whose storage needs exceed a call frame. A program requests space there, while a fixed-size pointer on the stack records where the data lives. section 2.1
Heap memory differs from stack memory in several practical ways:
- It can hold data of any size, unlike the stack, which needs each variable’s exact size at compile time. section 2.1
- It is usually slower than the stack because the computer follows a pointer to reach the data. section 2.1
- Small embedded devices may provide no heap because they have no operating system to request heap memory from. section 2.1
Known-size and variable-size data
An i32 always occupies four bytes, so it can live directly on the stack. Data whose size is unknown at compile time goes in the heap, while a stack pointer leads the computer to it. section 2.1






