liveBook · Manning

Heap

As explained in Systems Programming with Zig

Heap memory is dynamically managed storage requested during program execution for data whose size or lifetime is not fixed by a function call.

When data size is unknown, heap memory provides storage beyond the limited stack. A program can request it from the operating system through system calls. section 3.1.2

An allocator manages memory blocks through a common interface. After using a block, free it so the allocator can reuse it. Zig makes allocation explicit; in C and most languages, a runtime allocator usually handles heap operations. section 3.1.2

Figure 3.1 Memory as seen by a process
CH03 F02 hinsonhasty

Shows memory from a process’s perspective. section 3.1.2

How Systems Programming with Zig covers it

How deep it goes
Defines heap requests, allocator-managed blocks, system calls, and freeing for reuse without detailing allocation algorithms.
Examples
Uses huge arrays as an example of stack overflow and contrasts runtime allocation in C with explicit allocation in Zig.
What you can do after
Apply allocators to request memory and free it for reuse.
How it connects
Connects heap memory to stack memory, allocators, system calls, and Zig’s explicit allocation model.

Also explained in

Compare how 11 books explain heap →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.