Hi,
Thanks for your detailed explanations.
I was paying with your nice example.
Currently my structure is keeping only several floats, ints and unsigned
ints. Following the Interprocess documentation, as you wrote, I can put
them directly into shared memory:
server_side:
P.insert(particleID(0,0));
P.insert(particleID(-1,1));
P.insert(particleID(-2,2));
P.insert(particleID(-3,3));
try{
//Erase previous shared memory
shared_memory_object::remove("shared_memory");
//Create a shared memory object.
shared_memory_object shm (create_only, "shared_memory", read_write);
//Set size
size_t P_len=P.size()*sizeof(particleID);
shm.truncate(P_len);
//Map the whole shared memory in this process
mapped_region region(shm, read_write);
//Write all the memory to 1
std::memset(region.get_address(), 1, region.get_size());
print_out_by<ID>(P);
boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec += 100;
for(;;)boost::thread::sleep(xt);
}
catch(interprocess_exception &ex){
shared_memory_object::remove("shared_memory");
std::cout << ex.what() << std::endl;
return 1;
}
Now I am trying to access the memory from client:
shared_memory_object shm (open_only, "shared_memory", read_only);
//Map the whole shared memory in this process
mapped_region region(shm, read_only);
//Check that memory was initialized to 1
const particlesID_set *P =
static_cast
arm2arm
writes: Hello, I would like to load multiindex container by one process lets say serverside_loader. And access that array by another clientside_analyser process? How to do that?
Hi Arman,
Yes, this can be done. There's an example that shows you how to do it:
http://www.boost.org/libs/multi_index/doc/examples.html#example12
Basically, you've got to take care of three things:
* The element type (particleID in this case) must be placeable in shared memory, see
for info on the limitations imposed on such objects. particleID is a simple class and can be directly put in shared memory. * You must use a special Boost.Interprocess allocator for the multi-index container. Use the aforementioned example as a guide. * Access to the container must be properly synchronized, just as you'd do for instance in a multi-threaded program.
Good luck with your project, come back if you have some difficulty.
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users