On 29/11/2010 6:01, Aditya Gadre wrote:
I have a question about Boost.Interprocess library. I am sharing a fixed size boost::interprocess::vector using managed_shared_memory. The vector length is 100 and the type of element in the vector is boost::array
. That makes (vector::size)*sizeof(boost::array = 100*8 = 800. . If I create a managed_shared_memory segment with length 800 bytes and create a vector in that segment, then boost::interprocess::bad_alloc is thrown. If however I create a segment with a length of say 8000 and then create the vector, then everything works well. So my question is what is the minimum size required for a managed_shared_memory segment apart from what the size of a vector?
There is a fixed overhead for the header and another one for each allocation (bookeeping information for deallocation), another overhead for each named object (you need to store the name, and other information...). You can also have memory fragmentation (if you allocate/deallocate many objects), just like with heap memory and this overhead is use-dependent. Take in care that the OS will reserve shared memory in page units (usually 4KB-64KB bytes, depending on HW/OS) so creating a segment of 800 will waste a whole page. See mapped_region::get_page_size() to know the size of a page in your platform. Best, Ion