Heaps Don’t Lie - Guidelines for Memory Allocation in C++
summary
Claims ten concrete rules: prefer stack allocation because it’s a one-register add; avoid malloc in hot/parallel sections because system calls and swapping can be ~10x–1000x slower and cause millisecond stalls; Windows CRT malloc serializes (use mimalloc as a drop-in); reserve containers when final size is known but don’t overuse reserve in tight loops; prefer output-parameter reuse to returning temporary vectors; consider a monotonic allocator/PMR for scoped, budgeted workloads but avoid reimplementing a full malloc.
AI-written summary · about
chapters (24)
- 0:00Introduction
- 0:57Heaps don't lie
- 4:13Understanding allocation
- 6:32Stack allocation
- 9:26Stack limitations
- 11:39Heap allocation basics
- 13:16Malloc performance
- 19:38Custom allocators
- 21:56Windows allocation issues
- 25:30Allocation pitfalls
- 29:12Pathfinding example
- 33:15Reserve vs growth
- 36:43Optimizing search
- 39:24Output parameters
- 40:56Reusing memory
- 43:04Clearing structures
- 46:05Memory management
- 50:08Custom allocators
- 51:22Dynamic stack memory
- 52:38Alloca pitfalls
- 55:11Monotonic allocator
- 1:00:00Budgeting resources
- 1:01:56Free lists
- 1:05:55Conclusion
related talks
01h 01mRecipes for Reducing Allocations by C++ Containers
49mMost Malleable Memory Management Method in C++
01h 25mTaming Dynamic Memory - An Introduction to Custom Allocators
01h 01mAllocators: The Good Parts
44mC++ Performance and Optimisation
01h 03mMost Malleable Memory Management Method
01h 01mGetting Allocators out of Our Way
01h 04mHow to Write a Custom Allocator
