1
I’m trying to use a Std::map that allocates objects within a file mapped using boost, with a vector worked but with a map not
#include <boost/interprocess/managed_mapped_file.hpp>
#include <map>
#include <iostream>
namespace bi = boost::interprocess;
using namespace std;
int main() {
std::string vecFile = "file_mapped.dat";
bi::managed_mapped_file file_vec(bi::open_or_create,vecFile.c_str(), 1000);
typedef bi::allocator<std::pair<string, string>, bi::managed_mapped_file::segment_manager> int_alloc;
typedef std::map<string, string, int_alloc> MyMap;
MyMap * mapptr = file_vec.find_or_construct<MyMap>("mymap")(file_vec.get_segment_manager());
(*mapptr)["aaa"] = "olahd";
mapptr->insert({"bbb", "98473"});
for(auto& par: *mapptr)
std::cout << par.second << std::endl;
}