~/talk

Heaps Don't Lie: Guidelines for Memory Allocation in C++

Talkat CppNorth 2025 · 2025-07-21..07-23· [c-and-cpp]
slides:none on file

About ten pragmatic rules: prefer stack allocation when size is known because it’s one register add; treat malloc as “fast except when it isn’t” because buckets, syscalls and swap can make it 10×–1000× slower; use mimalloc or another third‑party heap on Windows to avoid CRT lock contention; reserve final container sizes but don’t call reserve with a constant delta in a loop; reuse buffers and prefer output/reference parameters to avoid repeated allocations; avoid alloca for large or threaded work; favor explicit clear over assign‑to‑empty; and consider a monotonic allocator for scoped, budgeted resources.

AI-written summary · about

  1. 0:00Introduction and setup
  2. 1:58About the speaker
  3. 3:02Why heap allocation matters
  4. 8:17Stack vs heap allocation
  5. 15:03Heap allocation unpredictability
  6. 18:58Third-party heap implementations
  7. 24:40Reserve container size wisely
  8. 26:49Avoid reserve in loops
  9. 29:01Output parameters over containers
  10. 31:50Reuse allocations to save memory
  11. 36:43Clear over assign to empty
  12. 37:25Custom memory allocators overview
  13. 41:40Monotonic allocators explained
  14. 46:19When to use monotonic allocators
  15. 48:04Summary and final advice
  16. 48:50Q&A session
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.