Closed WDMdanila closed 3 years ago
It isn't expected an object can use sizeof(T) because of several reasons, just like T *p = new T
doesn't use sizeof(T) bytes from the heap:
In general, there is no formula to precisely know how much memory you will end up using, just like you don't exactly know how much heap you will consume with dynamic allocation using new/delete/malloc/free.
Thank you very much for quite in-depth explanation and such a quick response!
Boost version: 1.76.0 Operating System: Ubuntu / Debian Language: C++20, C++17
Expected behaviour
Object
T
created inboost::interprocess::managed_shared_memory
requires thatmanaged_shared_memory
should be exactlysizeof(T)
Actual behaviour
When creating
boost::interprocess::managed_shared_memory
for storing shared objects with:we get this error:
boost::interprocess::bad_alloc
After some testing and examination we found out that extra space required was
492
bytes and that it would change in increments of100
and exact size depends on the name of object created.Question itself
Could someone explain what is going on and how could we calculate exactly how much space
boost::interprocess::managed_shared_memory
should have in advance?