r/cpp • u/sporacid • Mar 21 '26
Slot map implementation for C++20
I've just finished submitting the initial version of my slot map implementation, based on this post. A slot map is a data structure that provides stable and versioned keys to stored values. Inserting into the map creates and return a unique key, which stays valid until the slot is explicitly freed.
I hope someone will find this useful :)
https://github.com/sporacid/slot-map
EDIT: As suggested by some of you, I've added benchmarks to compare to plf::colony. As i did those benchmarks, I had to work on a bunch of optomizations to compete, and I've introduce a static storage that has a fixed number of slots, and I kept the original dynamic storage with a fixed number of blocks, but the blcoks are allocated as needed. Let me know what you think!
View all comments
Show parent comment
2
u/RogerV Mar 22 '26 edited Mar 22 '26
that is a huge factor for my program (DPDK networking) - it was a crucial factor in implementing an internal inter-thread messaging system where control plane threads, which are conventional OS native threads, are able to do synchronous request/response messaging with the data plane DPDK lcore worker pool threads.
The control plane thread domain is conventional - they can block, do sys calls (transition to kernel space), do heap allocations, use any feature of C++
The data plane DPDK lcore thread domain never block, never take locks, avoid sys calls (transition to kernel space), never do heap allocations. So when they’ve received a message from the control plane and respond with a response message, they adhere to all these restrictions.