Recipes for Reducing Allocations by C++ Containers
summary
Shows concrete fixes and measurements: use malloc breakpoints in lldb or dtrace to count allocations (one toy push_back example allocates eight times), prefer reserve and iterator-aware constructors, use views to avoid copies, exploit SSO (string stops allocating at ~23 bytes on that libc), and try small_vector (faster when truly small, slower under heavy push_back due to branch overhead). Demonstrates pmr use: a monotonic_buffer_resource with a stack buffer sized roughly nsizeof(pair)+5sizeof(key) cuts malloc call count and wall time for unordered_map inserts in benchmarks. Warns about scope promotion, const loss and threading.
AI-written summary · about
chapters (16)
- 0:00Performance and allocations
- 1:12Performance in autonomy software
- 7:57Heap vs stack in C++
- 10:30Measuring allocations
- 15:42Reduce vector reallocations
- 20:55Stack space with std::array
- 23:01Small string optimization
- 28:39Avoid accidental copies
- 31:48Right container constructors
- 34:43Small vector for stack
- 38:17Reuse buffers across scopes
- 42:50Thread-local scratch buffers
- 45:19Custom stack containers
- 47:29Monotonic PMR for nodes
- 56:36Nested PMR containers
- 1:00:31Q&A
related talks
01h 01mAllocators: The Good Parts
01h 01mGetting Allocators out of Our Way
49mMost Malleable Memory Management Method in C++
01h 03mMost Malleable Memory Management Method
01h 25mTaming Dynamic Memory - An Introduction to Custom Allocators
44mC++ Performance and Optimisation
01h 11mDynamic Memory Allocation Challenges in C++ Safety Critical Systems
01h 08mHeaps Don’t Lie - Guidelines for Memory Allocation in C++
