Stack and heap
After load the image is almost fixed. Data whose size and lifetime are known only at run time needs the heap. Static storage lives in .data/.bss; automatic in a stack frame; allocated from malloc until free. Returning a pointer to a local array is wrong: the frame is gone. In the note’s example the main-thread stack is 8176 KiB.
Internal fragmentation is waste inside blocks; external fragmentation is free memory in pieces too small to use. In the worked example 80 free bytes could not serve a 72-byte block.
free(p) receives only an address. The allocator therefore stores the block’s size just before the payload, in a header. Because every block size is a multiple of 8, the three lowest bits of the size are always zero, and the lowest one can record whether the block is allocated: a header value of 25 means a 24-byte block in use, 24 a 24-byte free block (Bryant and O’Hallaron, 2016, §9.9.6). In the allocator of this note the header is 4 bytes and the block size counts the header too.