
hgdhfdghsa@Safe-mail.net wrote:
Hello again,
I have one managed_shared_memory, which contains exactly one instance of a certain structure, allocated via MySegment.find_or_construct<TheClass>(interprocess::unique_instance)(...); How can I determine how big the segment must be?
Sorry, there is no way to get that. I agree that if you are going to allocate a single object, the information is useful. If you have several objects and the memory is fragmented, that information is not very useful. Overhead depends on: -> The shared memory allocation algorithm -> The internal indexes to hold named and unique instances. If you are using non-intrusive indexes, like flat_map_index which needs contiguous memory, the real memory depends on the reallocations and contiguous memory portions that are free. With the default index (which is an intrusive container) the overhead is fixed and does not depend on the memory layout. I'll add it to my to-do list. You'll need to use a safe value meanwhile (try and guess). 100*sizeof(void*) bytes will be enough. Take in care that shared memory is really allocated with shared_memory_object::page_size granularity, so allocating 1 byte shared memory wastes one page (4 or 64 KB depending on the operating system). Use mapped_region::get_page_size() to know the page size. Regards, Ion