Phase 1 of 4 · Study weeks 1-4
The object model, memory and undefined behaviour
This phase makes the first checkpoint possible: a core that the sanitizers pass and that allocates nothing on the hot path.
Topics every week
- Week 18 h
- Value categories, move semantics and copy elision
- Object lifetime and dangling references
- Undefined behaviour and what optimisers do with it
Hand inA catalogue of six undefined behaviours, each with a test and the assembly
- Week 28 h
- Object layout, alignment and padding
- Templates, concepts and compile-time cost
constexpr- Error handling: exceptions,
std::expectedand error codes
Hand inThe message structs laid out and checked with
static_assertand a size table - Week 38 h
- Sanitizers (ASan, UBSan, MSan) and what each misses
- Static analysis with clang-tidy
- Compiler warnings as errors
- Reading a sanitizer report
Hand inThe parser and book running clean under sanitizers in CI, with two seeded bugs
- Week 48 h
- Allocators and
std::pmr - Arenas and small-object optimisation
- Smart pointer costs
- Counting allocations
Hand inCheckpoint 1: the correct core, the allocation counter and the catalogue
- Allocators and
Practice projects
- Practice 1, the undefined-behaviour catalogue (Weeks 1 and 2): write six cases (signed overflow, out-of-bounds, use after free, a dangling reference into a growing vector, an uninitialised read, a violated aliasing rule). Done when: each has a test, a sanitizer or compiler flag that catches it, and the assembly that shows the optimiser's effect.
- Practice 2, the sanitizer matrix (Week 3): run the tests under ASan, UBSan and a plain build. Done when: CI fails on a seeded use-after-free and on a seeded signed overflow, and passes after both are fixed.
- Practice 3, the allocation counter (Week 4): replace global
operator newin a test build to count calls. Done when: the hot path shows zero allocations after warm-up over 10 million messages. - Optional, a
pmrarena: build the order storage on a monotonic resource. Done when: a benchmark shows the allocation cost before and after.
GitHub repos to study
Existence and last commit were checked on 22 Nov 2026 by shallow clone. Every repository below had a commit in the last six months. Look at the README for archive notices before you rely on one.
| Repo | What to read | Week |
|---|---|---|
| llvm/llvm-project | The compiler-rt sanitizer runtimes and the Clang diagnostics | 3 |
| microsoft/STL | A readable standard library: containers, variant and atomics | 2 |
| abseil/abseil-cpp | The flat hash map and how it handles layout and hashing | 4 |
Milestone checkpoint
Build Checkpoint 1. Write the reference feed generator and the tests first. Add the parser, one order book and the allocation counter. Add the two seeded bugs and watch CI fail. Hand in the six-case catalogue, the sanitizer CI output, ADR-1 (error handling strategy) and ADR-2 (storage and allocation).
Check yourself
Answer each question in your head first, then open it to check.
Why can code that overflows a signed integer behave differently at
-O0and-O2?Signed overflow is undefined, so the optimiser may assume it never happens and remove checks or reorder code that depends on it. At-O0that code is left alone.What does
std::moveactually do?It casts to an rvalue reference. It moves nothing by itself; a move constructor or assignment does the move when one is selected.What does ASan miss that MSan or UBSan catch?
ASan finds invalid memory access. UBSan finds undefined arithmetic and shifts. MSan finds reads of uninitialised memory.When does a reference into a
std::vectorbecome invalid?When the vector reallocates, which happens on apush_backthat exceeds capacity. The old storage is freed and references into it dangle.Why count allocations instead of timing the function?
A time depends on the machine and on noise. A count is exact and does not change between runs, so it can fail a test.