I have an object that I’m storing in shared memory that contains a map data member whose values are lists. The processes that interact with this object don’t have direct access to the map data structure. Instead, the object is accessed
and modified through its public interface. The issue I am running into is how to handle new key, value insertions. I would prefer to leave the fact that the object is in shared memory an implementation detail, but in order to construct a new list to insert
in the map, the list needs to be initialized with an allocator using the segment manger. Unless I pass that segment manager into every method that might add a new list to the map, I’m struggling how to get it working. I can’t simply store a pointer to the
managed shared memory or segment manager within the class since the address would only be valid in the process that constructed it.
The only possible implementations I can think of would be to require passing in the segment manager into all of the methods and then create a simple wrapper class that contains a pointer to this object along with a pointer to the segment
manager. The wrapper class would essentially “duplicate” each of the methods in the wrapped class but drop the segement manager parameter since it has it as a member. Processes that “find” this object in shared memory would then be responsible for wrapping
it in an object of the wrapper class. The other possible implementation would be to always open the shared memory segment by name before modifying the map.
Josh