~/talk

Recipes for Reducing Allocations by C++ Containers

Talkat C++ on Sea 2022 · 2022-07-05..07-07· [c-and-cpp]
links:none on file
slides:none on file

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

  1. 0:00Performance and allocations
  2. 1:12Performance in autonomy software
  3. 7:57Heap vs stack in C++
  4. 10:30Measuring allocations
  5. 15:42Reduce vector reallocations
  6. 20:55Stack space with std::array
  7. 23:01Small string optimization
  8. 28:39Avoid accidental copies
  9. 31:48Right container constructors
  10. 34:43Small vector for stack
  11. 38:17Reuse buffers across scopes
  12. 42:50Thread-local scratch buffers
  13. 45:19Custom stack containers
  14. 47:29Monotonic PMR for nodes
  15. 56:36Nested PMR containers
  16. 1:00:31Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 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
?
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.