I have a mmap typecast to a char pointer
char *ptr;
ptr = (char *)mmap(0, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
This was my earlier code. But now I want to use a map instead of char * as the requirements changed.
Now, my map is declared as
map < int, string > i_s_map;
How do I change my mmap call to point to the map?
You don’t want to store STL containers in shared memory, at least not share them. The reason is that they rely heavily on heap allocation, so out-of-the-box
std::mapwill hold pointers from virtual address space of a different process.Take a look at
boost::interprocessfor a way to deal with this situation in C++.