r/cpp • • Oct 22 '26

These Bees Make the Wrong C++

https://dalerank.github.io/en/articles/wrong-cpp-bees.html
68 Upvotes

15 comments sorted by

View all comments

Show parent comment

1

u/johannes1971 Oct 22 '26

Is every byte of memory pre-allocated in that startup buffer? Or are you running your own allocator inside it?

6

u/theblancmange Oct 22 '26

I work on safety critical and realtime c++. We allocate every non-stack byte at startup. If you want something like std::shared_ptr, you provide an allocator that retrieves and replaces memory from a pool. I essentially only use vectors for things like configuration at startup. maps, sets, etc get preallocated.

1

u/remy_porter Oct 22 '26

I've done both options. The latter would be a simple arena allocator, and that's probably a case where we're not going to recover from it.

1

u/aoi_saboten Oct 24 '26

You can use mimalloc to preallocate a space with MIMALLOC_RESERVE_OS_MEMORY=N and prohibit from requesting more with MIMALLOC_LIMIT_OS_ALLOC env variables or equivalent functions and override malloc/free, new/delete