knaxuslearn · build · ship

Roadmaps / C++ / Phase 1

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

  1. 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

  2. Week 28 h
    • Object layout, alignment and padding
    • Templates, concepts and compile-time cost
    • constexpr
    • Error handling: exceptions, std::expected and error codes

    Hand inThe message structs laid out and checked with static_assert and a size table

  3. 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

  4. 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

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 new in a test build to count calls. Done when: the hot path shows zero allocations after warm-up over 10 million messages.
  • Optional, a pmr arena: 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.

RepoWhat to readWeek
llvm/llvm-projectThe compiler-rt sanitizer runtimes and the Clang diagnostics3
microsoft/STLA readable standard library: containers, variant and atomics2
abseil/abseil-cppThe flat hash map and how it handles layout and hashing4

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.

  1. Why can code that overflows a signed integer behave differently at -O0 and -O2?
    Signed overflow is undefined, so the optimiser may assume it never happens and remove checks or reorder code that depends on it. At -O0 that code is left alone.
  2. What does std::move actually do?
    It casts to an rvalue reference. It moves nothing by itself; a move constructor or assignment does the move when one is selected.
  3. 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.
  4. When does a reference into a std::vector become invalid?
    When the vector reallocates, which happens on a push_back that exceeds capacity. The old storage is freed and references into it dangle.
  5. 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.