Index

Module 05 · How Computers WorkBuild the machine's software

Build malloc, then a garbage collector

How Code Becomes Execution
How Code Becomes Execution · Open board

The two work areas a running program keeps: a stack that empties itself when a call returns, and a heap where things stay until someone says they are done. This lesson builds the part that hands out the heap and takes it back.

Before you start. A running program keeps two work areas in memory. The stack holds calls that have not finished, and empties itself as they return. The heap holds anything that must outlive the call that made it, and keeps it until the program gives it back. Forgetting to give it back is a leak. Using it after giving it back is a use-after-free (How Code Becomes Execution (compilers, stack & heap)). The kernel, the one program in charge of the hardware, hands out memory only in whole pages of several kilobytes, so something inside the program must cut pages into the small pieces it asks for (The address book every process carries). The first part of this build wrote a computer as a loop in Go (Build a stack machine); this part needs Go too, and nothing else from that one.

Continue reading with a plan

The first three lessons of every track are free. This lesson is included with a plan, which unlocks every lesson, board, video, lab and paper for one price.

View plans →Already a member? Sign in

Review How Computers Work →

Saved in this browser, and to your account when you sign in.