I create a map<int, vector<int>> in a Boost Interprocess managed_shared_memory in one process and then want to open it in another process to write to it continually.
The other process tries to open the shared memory in the constructor of an object Communication and then presents a method addData(int _data).
Example:
// Typedefs for shared data structures
using boost::interprocess;
using std::pair;
using std::scoped_allocator_adaptor;
typedef managed_shared_memory::segment_manager man;
typedef allocator <int , man> Int_Allocator;
typedef vector <int, Int_Allocator> Int_Vector;
typedef pair <const int, Int_Vector> Int_Vector_Map_Type;
typedef scoped_allocator_adaptor <allocator<Int_Vector_Map_Type, man>> Int_Vector_Map_Type_Allocator;
typedef map <int, Int_Vector, std::less<int>, Int_Vector_Map_Type_Allocator> Int_Vector_Map;
// Let's call this process 'parent'
managed_shared_memory segment(create_only, "Shared");
Int_Vector_Map_Type_Allocator alloc = segment.get_segment_manager();
segment.construct<Int_Vector_Map>("Map")(std::less<int>(), alloc);
// 'child' process
class Communciation{
Int_Vector_Map* map;
public:
Communication{
managed_shared_memory segment(open_only, "Shared");
map = segment.find<Int_Vector_Map>("Map").first;
}
void addData(int _key, int _value){
if(map->size() == 0 || map->find(_key) == map->end(){
managed_shared_memory segment(open_only, "Shared");
Int_Allocator alloc = segment.get_segment_manager();
map->insert(Int_Vector_Map_Type(_key, Int_Vector(alloc)));
} // create the vector and its allocator, otherwise runtime error
map->at(_key).push_back(_value);
}
}
This is a broken down example of what I am looking at, but I do not see the immediate error.
When trying to run this code I get the runtime error "Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address (...)".
Changing the addData(...) method to:
void addData(int _key, int _value){
managed_shared_memory segment(open_only, "Shared");
map = segment.find<Int_Vector_Map>("Map").first;
if(map->size() == 0 || map->find(_key) == map->end(){
Int_Allocator alloc = segment.get_segment_manager();
map->insert(Int_Vector_Map_Type(_key, Int_Vector(alloc)));
} // create the vector and its allocator, otherwise runtime error
map->at(_key).push_back(_value);
}
i.e. opening the map every call fixes this issue but is not applicable in my case as I want to be able to call this method many times per frame without impacting fps too much.
What is the cause of this issue and is it even possible to use boost's interprocess as described?
Edit: For added context, the 'child' process is running in another process in which I inject a dll into.

vector<string>) did you trymultimap( orunordered_multimap) instead ofmap<int, vector>? cppreference example onscoped_allocator_adaptoruseadaptive_poolinstead ofallocator. I guess you need more tags; scoped_allocator_adaptor and boost.interprocess included.