Hi Ion, How can i solve my pblm? I tried many things but nothing seems to be working. Regards Manish manish4gupta wrote:
I am loading the map into memory with one program and retrieving the map values by another program.
Process1. #include
#include #include #include #include #include <iostream> using namespace boost::interprocess;
//Typedefs of allocators and containers typedef managed_shared_memory::segment_manager segment_manager_t; typedef allocator
void_allocator; typedef allocator int_allocator; typedef vector int_vector; typedef allocator int_vector_allocator; typedef vector int_vector_vector; typedef allocator char_allocator; typedef basic_string char_string; class complex_data { int id_; char_string char_string_; int_vector_vector int_vector_vector_;
public: //Since void_allocator is convertible to any other allocator<T>, we can simplify //the initialization taking just one allocator for all inner containers. complex_data(int id, const char *name, const void_allocator &void_alloc) : id_(id), char_string_(name, void_alloc), int_vector_vector_(void_alloc) {} //Other members... };
//Definition of the map holding a string as key and complex_data as mapped type typedef std::pair
map_value_type; typedef std::pair movable_to_map_value_type; typedef allocator map_value_type_allocator; typedef map< char_string, int , std::less , map_value_type_allocator> complex_map_type; int main () { //Remove shared memory on construction and destruction struct shm_remove { shm_remove() { shared_memory_object::remove("MySharedMemory"); } ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); } } remover;
//Create shared memory managed_shared_memory segment(create_only,"MySharedMemory", 65536);
//An allocator convertible to any allocator
type void_allocator alloc_inst (segment.get_segment_manager()); //Construct the shared memory map and fill it complex_map_type *mymap = segment.construct
//(object name), (first ctor parameter, second ctor parameter) ("MyMap")(std::less (), alloc_inst); std::string s = "test"; char_string cs(s.c_str(), alloc_inst); //string y (cs.c_str()); //std::cout << y <<"\n"; // = (char_string)s;
for(int i = 0; i < 100; ++i) { mymap->insert(std::pair
(cs , i)); //char_string key_object(alloc_inst); //map_value_type value(key_object, i); // mymap->insert(value); } return 0; } Process2. #include
#include #include #include #include #include <iostream> #include #include <algorithm> using namespace boost::interprocess; typedef managed_shared_memory::segment_manager segment_manager_t; typedef allocator void_allocator; typedef allocator int_allocator; typedef vector int_vector; typedef allocator int_vector_allocator; typedef vector int_vector_vector; typedef allocator char_allocator; typedef basic_string char_string; class complex_data { int id_; char_string char_string_; int_vector_vector int_vector_vector_; public: complex_data(int id, const char *name, const void_allocator &void_alloc): id_(id), char_string_(name, void_alloc), int_vector_vector_(void_alloc) {} };
typedef std::pair
map_value_type; typedef std::pair movable_to_map_value_type; typedef allocator map_value_type_allocator; typedef map< char_string, int,std::less , map_value_type_allocator> complex_map_type; int main () { using namespace boost::interprocess; try { managed_shared_memory segment(open_only ,"MySharedMemory"); typedef map< char_string, int, std::less
, map_value_type_allocator> complex_map_type; complex_map_type *MyMap = segment.find ("MyMap").first; for (complex_map_type::iterator it = MyMap->begin(); it != MyMap->end(); it++) { std::cout << it->first << "\n"; } segment.destroy ("MyMap"); } catch(...) { shared_memory_object::remove("MySharedMemory"); throw; } shared_memory_object::remove("MySharedMemory"); return 0; } But i am getting the following error message
terminate called after throwing an instance of 'boost::interprocess::interprocess_exception' what(): No such file or directory Aborted
What is the reason for this? Thanks in advance.
-- View this message in context: http://www.nabble.com/How-to-Read-the-stored-memory-map-in-C%2B%2B-tp2550632... Sent from the Boost - Users mailing list archive at Nabble.com.