Expert · Module 13
Allocators, Lock-Free Queues and Benchmarks
Replace the default allocator, build a lock-free queue, and benchmark honestly against the standard library.
new is a general-purpose compromise; a measured workload may benefit from a narrower allocation strategy. This module begins by measuring allocation costs, then builds a pool allocator and a lock-free queue, examines memory reclamation, and compares the result with standard-library alternatives using a reproducible benchmark harness.
- 1Why Allocation Dominates: Measuring new and vectorPro — members onlyMeasure new and delete against vector growth, see where doubling copies and heap calls dominate runtime, and learn when allocation deserves replacement.10 min
- 2A Pool Allocator for Fixed-Size NodesPro — members onlyBuild a fixed-size pool with a free list, allocate and deallocate in constant time, and test it against new for one node type.10 min
- 3Lock-Free Queues: Compare-Exchange and ReclamationPro — members onlySketch a Michael-Scott queue with compare_exchange_weak, see why ABA breaks naive reclamation, and compare hazard pointers with epoch schemes.11 min
- 4Benchmarking: Clocks, Warmup and Honest NumbersPro — members onlyTime C++ code with high-resolution clocks, defeat optimizer tricks, warm up caches, and report numbers that survive a rerun.10 min
- 5Project: Allocator Plus Queue Versus STLPro — members onlyRun an honest A/B of a pool plus lock-free queue against a mutex-protected STL queue, interleaved with medians, across three thread shapes before declaring a winner.12 min
- 6Polymorphic Allocators: std::pmr in Real ContainersPro — members onlyRoute many standard containers through a memory resource, choose monotonic or pooled storage deliberately, and keep resource lifetimes valid.11 min