I am creating a shared interprocess map using boost::interprocess. For this I create an allocator from the segment_manager of the shared memory segment where the map is located.
The element value type of the map is a basic_string which is itself templated to use a char allocator created from the same segment manager. In one process I create the map and in the other I search for an item using the maps iterator in that process and in some cases I call map::erase with the iterator.
This causes an access violation exception and I know that I am making the call with a valid iterator. The access violation occurs in the call to the destructor of the basic_string that is the 'second' of the 'pair' pointed to by the iterator. When I perform the same erase operation using an iterator in the writing process immediately after insertion there is no access violation.
It looks as though the reading process is trying to release the memory of the element using the element's allocator, which was created in the writing process whereas that allocator is only valid in the process that created it.
Does this mean that the allocators themselves cannot be shared?
I would have expected that allocator to be usable in both processes as its state should contain only relative pointers that are valid in both processes. If not, how can I share elements that use shared memory (heap) allocations between processes? Should I have created those allocators in a special way in the writing process before passing them to the basic_string elements to allow me to use them in anerase operation in another process?
What else might be causing the access violation?