~/talk

Designing a Slimmer Vector of C++ Variants

Talkat C++Now 2024 · 2024-04-29..05-03· [c-and-cpp]
links:none on file
slides:none on file

Shows a working library that replaces std::vector<std::variant<...>> with a contiguous, bit-packed storage plus compact offset/type metadata, trading some runtime cost for far lower memory use. Benchmarks report reducing a 20 KB pessimistic case to about 45 bytes (≈20% over theoretical min) for the example mix, handling alignment, dynamic offset resizing, and offering bit-packed replacement APIs (do_get/visit/replace) instead of assignment-through-operator[]; insert/erase require careful realignment and overlapping-move handling.

AI-written summary · about

  1. 0:00Introduction
  2. 0:22Motivation for problem
  3. 6:21Design 1: Heap-allocated variant
  4. 10:52Design 2: Vector-aware variant
  5. 11:57Design 3: Tracking offsets and types
  6. 16:50Memory alignment challenges
  7. 21:40Design 4: Proper alignment
  8. 24:28Design 5: Bit-packing metadata
  9. 33:13Performance implications
  10. 39:30API design challenges
  11. 54:14Insert and erase complexities
  12. 1:05:10Subscript operator issues
  13. 1:15:01Benchmarks and results
  14. 1:21:35Final design summary
  15. 1:28:41Lessons learned
~/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.