Thanks it works as suggested. I was in trouble from past 2 weeks but u helped me. Once again thank you very much. Roland Bock-2 wrote:
manish4gupta wrote:
Previously i was doing in the same way but still getting the same error. I was removing he shared region in process2 only but pblm is still there.Pls can i get any working example doing the same. Process1. storing map
nad process2 reading it.I will really be thankful to you. Christoph Gysin-3 wrote:
2009/9/25 manish4gupta
: How can i solve my pblm? I tried many things but nothing seems to be working. Calling shared_memory_object::remove("MySharedMemory") removes the whole shared memory where you saved your data. If it gets called before Process2 tries to read it, it will fail with mentioned interprocess_exception.
Just don't remove it in Process1, remove it at the end of Process2.
Chris --
What Christoph wrote was correct:
In the code you posted on th 18th, process1 removes the shared memory on exit (when the object called "remover" goes out of scope). Thus, when you run process1 it brings the shared memory into being, writes the map into it and then removes the whole stuff again.
Thus, when you start process2 afterwards, the shared memory is long gone. Hence the exception.
So in the code posted on the 18th, you just have to replace the remover by the following line:
managed_shared_memory segment(create_only,"MySharedMemory", 65536);
That works.
BTW: In a "real world" application the remover would be a very useful helper class. If you do not know why, take a good book on C++, for instance "Effective C++" by Scott Meyers, and read until you do know :-)
Regards,
Roland
PS: And please(!) remove the unnecessary stuff, before posting. The complex_data class for instance is totally irrelevant. Same goes for most of the typedefs. All this nonsense just adds to the noise which makes it harder to see the actual problem.
PPS: Attached, please find the reduced code of process1.
#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 char_allocator; typedef basic_string char_string; //Definition of the map holding a string as key and complex_data as mapped type typedef std::pair
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 () { shared_memory_object::remove("MySharedMemory");
//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
("MyMap")(std::less (), alloc_inst); char_string cs("test", alloc_inst); for(int i = 0; i < 100; ++i) { mymap->insert(std::pair
(cs , i)); } return 0; } _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- 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.