| Section | Title |
|---|---|
| 1 | Memory Model Basics |
| 2 | Single Item Pointers |
| 3 | Many Item Pointers |
| 4 | Slices |
| 5 | Optional Pointers |
| 6 | Pointer Arithmetic |
| 7 | Alignment |
| 8 | Sentinel-Terminated Arrays |
| 9 | Stack vs Heap |
| 10 | Dangling Pointers |
| 11 | Memory Safety in Zig |
| 12 | Volatile and Atomic Memory |
Memory Model BasicsMemory is where a program keeps its data while it runs.
Single Item PointersA pointer is a value that stores the address of another value.
Many Item PointersA many item pointer is a pointer that can move across several values of the same type.
SlicesA slice is a view into a sequence of values.
Optional PointersAn optional pointer is a pointer that may have no value.
Pointer ArithmeticPointer arithmetic means moving a pointer forward or backward through memory.
AlignmentAlignment is a rule about where a value may be placed in memory.
Sentinel-Terminated ArraysA sentinel-terminated array is an array with a special value at the end.
Stack vs HeapZig programs use memory in different places. The two most important places are the stack and the heap.
Dangling PointersA dangling pointer is a pointer that refers to memory that is no longer valid.
Memory Safety in ZigMemory safety means using memory only while it is valid, only through the right type, and only inside the allowed range.
Volatile and Atomic MemoryMost memory in Zig is ordinary memory.