brain

tamnd's digital brain — notes, problems, research

42734 notes

V8 Pointer Compression Cage

A direct ancestor of vm3's 32-bit slab index. V8 squeezes 64-bit pointers down to 32-bit offsets within a per-isolate 4 GB virtual region (the "cage"). Cut V8's heap by 43%, Chrome renderer memory by 20%.

memory-safetyruntime
CakeML and the Verified-JIT Line

The bootstrapping verified ML compiler, its 2024 PLDI agenda, and the FM-JIT verified-JIT effort that builds on it.

memory-safetyverification
Hylo (formerly Val)

Mutable value semantics with subscript-based projection borrowing, no lifetime variables, and the Law of Exclusivity enforced at call sites.

memory-safetyownership
Pony Reference Capabilities

Six capabilities (iso, trn, ref, val, box, tag) make actor-based concurrency data-race-free at compile time. Production at WallarooLabs and Microsoft; foundation for Verona's region work.

memory-safetyownership
Intel LAM (Linear Address Masking) and the x86 top-byte-tag story

Intel LAM (Linear Address Masking) and the x86 top-byte-tag story

memory-safetyhardware
WebAssembly Segmented Memory (and friends)

The CG-track answer to "what's beyond a single 4 GB linear memory?" Multiple memories shipped in Wasm 3.0 (Sep 2025). Memory64 shipped at the same time. A formal "segmented memory" proposal in the MSWasm vein has not yet entered the CG track but is influencing design.

memory-safetyruntime
Arm PAC + BTI

Arm PAC + BTI

memory-safetyhardware
Scudo & friends: hardened allocators in production

Scudo & friends: hardened allocators in production

memory-safetyhardware
Capability-Machine Formalism and Endorsement Relations

Cerise, the CHERI-C Coq memory model, and capability-safety logical relations as the formal model behind handle-based runtimes.

memory-safetyverification
EU Cyber Resilience Act and Memory Safety

The CRA's 2026-2027 enforcement timeline and the implicit pressure toward memory-safe languages.

memory-safetyindustry
Kani

AWS's bit-precise bounded model checker for Rust, deployed in CI on Firecracker and the standard library.

memory-safetyverification
curl, Daniel Stenberg, and the "Is C/C++ The Actual Problem?" Debate

Stenberg's curl CVE data, the Hyper / Rust experiment, and the unresolved 2026 question of whether memory-safe languages are the whole answer.

memory-safetyindustry
Creusot

A deductive verifier for safe Rust that compiles to Why3 and discharges to off-the-shelf SMT solvers.

memory-safetyverification
ZGC — Generational, Colored-Pointer GC (OpenJDK)

Java's flagship low-latency collector. Sub-millisecond pauses on multi-TB heaps via colored 64-bit pointers and concurrent everything.

memory-safetyruntime
Roc — Perceus in production-ish

The biggest real-world deployment of Perceus reference counting, layered with Morphic alias analysis and "seamless slices" so functional code rarely allocates.

memory-safetyruntime
Colophon

This book describes the Zig programming language as of Zig 0.16.

zigbook
Appendix J. Index

A

zigbook
Appendix I. Exercise Answers

These are short answers or sketches for selected exercises from the book. Many exercises have several reasonable solutions. The important part is clarity and correctness.

zigbook
Appendix H. Zig 0.16 Migration Notes

This appendix records the kinds of changes that matter when moving older Zig code to Zig 0.16. It is a practical checklist, not a full release history.

zigbook
Appendix G. Common Compiler Errors

Zig tries to report errors at the point where the program becomes invalid. Many messages are direct: a value has the wrong type, a variable is unused, an error was ignored, or...

zigbook
Appendix F. C Interop Reference

One of Zig's central goals is direct interoperability with C. Zig can call C code, compile C code, link system libraries, export functions to C, and translate C headers.

zigbook
Appendix E. Build System Reference

Zig builds programs with Zig code. The build script is named:

zigbook
Appendix D. Standard Library Map

The Zig standard library is imported as:

zigbook
Appendix C. Builtin Functions

Builtin functions are part of the language. Their names begin with @.

zigbook
Appendix B. Operators and Precedence

This appendix lists the common operators by use. When an expression is not obvious, use parentheses.

zigbook
Appendix A. Zig Syntax Summary

This appendix summarizes the core syntax of Zig 0.16. It is a compact reference, not a tutorial.

zigbook
Appendix A. Zig Syntax Summary

This appendix is a quick map of Zig syntax. It is not a grammar. The full Zig grammar is part of the official language reference. Zig 0.16 also keeps the language small enough...

zigbook
Where to Go From Here

The programs in this chapter are small, but they have the shape of larger Zig programs.

zigbook
A Parallel File Scanner

This section combines the ideas from the previous sections into one program structure.

zigbook
demo

A program is finished only when another machine can build and run it reliably.

zigbook
Exercises

Exercise 19-1. Write a program that overflows a u8 using +=. Run it in Debug mode and observe the panic.

zigbook
Designing Concurrent Programs

Threads are a mechanism, not a design.

zigbook
Benchmarking

A benchmark measures the cost of a program or operation. The result is useful only if the measurement is repeatable and the work being measured is clearly defined.

zigbook
FFI Safety

FFI means foreign function interface. It is the boundary where Zig calls code written in another language, or where another language calls Zig.

zigbook
Semaphores

A semaphore is a counter used for synchronization.

zigbook
Exercises

This section collects the chapter exercises into one working set.

zigbook
Exercises

Exercise 16-1. Write a C file containing this function:

zigbook
Testing Strategy

Tests should be close to the code they check. Zig makes this easy with test blocks.

zigbook
Packed Memory

A normal struct is laid out for efficient access.

zigbook
Thread Pools

Creating a thread is expensive.

zigbook
Release Modes

Zig can build the same source code in different optimization modes.

zigbook
ABI and Layout

A C program and a Zig program can share data only when both sides agree on layout.

zigbook
Exercises

These exercises use the material from Chapters 15.1 through 15.8. Most are small. The goal is to practice reading and writing build.zig files until the structure becomes familiar.

zigbook
Cross Builds

Zig can build for a different target than the machine running the compiler.

zigbook
Dependencies

A Zig package may depend on another package.

zigbook
Examples

Examples are small programs kept inside the project.

zigbook
Exercises

This section collects the exercises for Chapter 14.

zigbook
Testing Utilities

Zig has built-in support for tests.

zigbook
Process APIs

The standard library gives access to process information through std.process.

zigbook
Exercises

This section collects the exercises for the chapter.

zigbook
Zig 0.16 I/O Changes

Zig 0.16 changes how I/O code is written in the standard library.

zigbook
Filesystem APIs

The standard library gives access to files and directories through std.fs.

zigbook
Error Handling in I/O

Input and output can fail.

zigbook
A Static Library

A library is code meant to be used by another program. In Zig, a library can be built from the same kind of source files as an executable. The difference is in how the build...

zigbook
Volatile Memory

Most memory in a program behaves normally.

zigbook
Async Status in Zig 0.16

Zig once had async functions as a language feature.

zigbook
Static and Dynamic Linking

A program is made from object code.

zigbook
Calling Zig from C

C can call Zig when the Zig function is exported with a C-compatible ABI.

zigbook
Tests

Zig has tests in the language.

zigbook
Formatting

Zig uses format strings to turn values into text.

zigbook
Standard Input and Output

A program usually has three standard streams:

zigbook
Exercises

The exercises in this section are meant to make allocation habits precise. Each one should be written as a complete program unless stated otherwise.

zigbook
Ownership Rules

Allocation creates a responsibility.

zigbook
Fixed-Buffer Allocator

A fixed-buffer allocator uses memory that already exists.

zigbook
Arena Allocator

An arena allocator is used when many allocations have the same lifetime.

zigbook
Integer Overflow

An integer type can store only a fixed range of values.

zigbook
A Tiny HTTP Client

An HTTP client opens a network connection, sends a request, receives a response, and writes the response body.

zigbook
Condition Variables

A mutex protects shared data.

zigbook
libc and Freestanding Builds

A Zig target may use a C library, or it may use none.

zigbook
Linking Libraries

Calling a C function is only half the job. The linker must also find the code for that function.

zigbook
Build Options

A build option is a value passed to build.zig from the command line.

zigbook
Hash Maps

A hash map stores key-value pairs.

zigbook
Buffered I/O

Reading or writing one byte at a time is expensive.

zigbook
General-Purpose Allocator

The general-purpose allocator is used for ordinary heap allocation.

zigbook
Exercises

Exercise 11-1. Write a generic min function for values that support <.

zigbook
Compile-Time Dispatch

Generic functions in Zig are specialized at compile time.

zigbook
Interfaces by Convention

Zig has no built-in interface keyword.

zigbook
A Line Filter

A line filter reads text, changes or selects some lines, and writes the result. Many Unix programs have this shape.

zigbook
Pointer Casts

A pointer has a type.

zigbook
Atomics

A mutex makes one thread wait while another thread uses shared data.

zigbook
CPU Architectures

The architecture part of a target tells Zig what kind of processor the program will run on.

zigbook
Header Translation

@cImport does two jobs.

zigbook
Build Steps

A build file describes steps.

zigbook
`std.ArrayList`

std.ArrayList is a growable array.

zigbook
Writing Bytes

Writing bytes is the opposite of reading them.

zigbook
Page Allocator

The page allocator gets memory from the operating system.

zigbook
Type Constraints by Use

Zig does not have a formal trait or interface system.

zigbook
Exercises

1. Write a program that computes several Fibonacci numbers with comptime. Print the results at runtime.

zigbook
A File Copier

A file copier is a useful small program. It opens one file for reading, opens another file for writing, then copies bytes from the first to the second.

zigbook
Safety Checks

Zig inserts safety checks for operations that are valid only under certain conditions. These checks are present in safe build modes. They catch mistakes at the point where the...

zigbook
Mutexes

A mutex is a lock for shared data.

zigbook
Operating Systems

The operating system part of a target tells Zig what kind of system the program will run on.

zigbook
`@cImport`

Writing every C declaration by hand is tedious. Zig can read C headers directly.

zigbook
`build.zig`

The file build.zig is a Zig program.

zigbook
`std.mem`

The std.mem module contains operations on memory, slices, bytes, and basic data movement. Much of Zig programming eventually passes through std.mem.

zigbook
Reading Bytes

A file is read as bytes.

zigbook
The Allocator Interface

An allocator is a value that knows how to allocate and free memory.

zigbook
Generic Structs

A generic struct is a function that returns a type.

zigbook
Generating Declarations

A Zig function can return a type.

zigbook
A Command-Line Parser

Many programs begin the same way: they read command-line arguments, decide what the user requested, then execute an operation.

zigbook