I have a managed_shared_memory objects that holds the map container SharedMap defined as follows.
typedef std::pair<std::string, T> ValueType;
typedef allocator<ValueType, managed_shared_memory::segment_manager> ShmemAllocator;
typedef map<std::string, T, std::less<std::string>, ShmemAllocator> SharedMap;
My issue is I need to determine the size of shared memory that I am using. The key of the map is a std::string of unknown size, and the data is a template type of unknown size where each data will varying in size.
Can anyone suggest how I can keep track of the memory I am using?
I’m new to boost::interprocess so any suggestion will help greatly.
I solved the issue by using exception handling. I insert into the map until a
bad_allocexception is thrown. I catch the exception and re-size the shared memory.I used the method
static bool grow(const char *shmname, size_type extra_bytes)which should be a member function ofmanaged_shared_memory