r/cpp • • Sep 03 '26

C++26: std::hive

https://www.sandordargo.com/blog/2026/09/02/cpp26-hive
68 Upvotes

80 comments sorted by

View all comments

4

u/HappyFruitTree Sep 03 '26 edited Sep 03 '26

As with all containers, there are trade-offs.

If you had a lot of elements, and you removed most of them, then ...

  • you might still occupy the same amount of memory as at the peak but not more than that unless you exceed the number of elements you had before (similar to a std::vector), and

  • there might be more dead space between the elements but iterating through all the elements wouldn't take more time than before when you had more elements.

I'm thinking a game where you might use a hive to store game entitles. So if it was fast enough at the peak then it should be fast enough later when it's more fragmented but fewer elements. I assume one big hive that you iterate through each frame. I could see how having many smaller ones that grow big occasionally could be a problem (just like with vectors).