#include #include #include #include /////////////////////////////////////////////////////////// #define BOOST_DATE_TIME_NO_LIB 1 #include #include #include #include /////////////////////////////////////////////////////////// using std::cout; using std::endl; /** * If argc == 3 -> delete the shared memory segment. * If argc == 2 -> assign some data to the shared memory map. * Else write out the contents of the map. */ int main (int argc, char** argv) { if (argc == 3) { boost::interprocess::shared_memory_object::remove("SharedMem0x4"); return 1; } typedef char char_type; typedef std::basic_string string_type; typedef int key_type; typedef string_type mapped_type; //typedef float mapped_type; typedef std::pair value_type; typedef boost::interprocess::allocator< value_type , boost::interprocess::managed_shared_memory::segment_manager > allocator_type; typedef boost::interprocess::managed_shared_memory memory_type; typedef boost::interprocess::map< key_type, mapped_type, std::less, allocator_type > map_type; memory_type segment (boost::interprocess::open_or_create ,"SharedMem0x4" ,65536); allocator_type alloc_inst(segment.get_segment_manager()); const char_type* id = "ident"; map_type* smap = segment.find_or_construct(id) (std::less() ,alloc_inst); if (argc == 2) { //(*smap)[0] = 42; //(*smap)[2] = 39; (*smap)[0] = "blah"; (*smap)[2] = "wom"; } cout<< smap->size() << endl; for (map_type::const_iterator iter = smap->begin(), end = smap->end() ; iter != end ; ++iter ) { cout<< "(" << iter->first << ", " << iter->second << ") "; cout.flush(); } cout<< endl; return 0; }