|
Boost Users : |
Subject: [Boost-users] Creating interprocess::shared_ptr across processes
From: GxL (gabriel.levy_at_[hidden])
Date: 2011-04-17 23:10:36
Hi all,
I've been looking into the "boost::interprocess" library to use shared memory
the resides in a non-paged physical memory facilitated by RTX (Real-time
Windows extension). According to my understanding it's best to use
"managed_external_buffer".
I have managed to create the shared memory and create and share objects using
raw pointers.
I would however prefer using smart_ptr that is offered by the
boost::interprocess.
The problem I'm having is that I can create the shared pointer for any shared
object in one process but when I want to create it's counter-part in the other
process, it does not share the "share_count" with the original shared_ptr in
the first process.
For instance I tried to share a list of integers. So I used the
interprocess::list as "named" object and once I crated it (following that
"interprocess" documentation) I placed that pointer into a
interprocess::shared ptr that I created using the helper function
"make_managed_shared_ptr".
Now in another process I am able to get hold of the raw pointer to that same
list by looking up by the name but cant figure out (did lots of searches about
this to no avail) how to instantiate an interprocess::shared_ptr such that it
would get the same shared_count object.
When I use the "make_managed_shared_ptr" and pass in the raw pointer to the
shared object it will create one but with a new "shared_count" which is
obviously bad.
First I thought that the "make_managed_shared_ptr" is able to resolve and find
the already existing "shared_count" and link to that but figured it wasn't the
case. Then I thought maybe I need to instantiate the shared_ptr as a named
object and then retrieve the same object in another process but can't see the
"make_managed_shared_ptr" would support such concept.
Then I thought maybe the pre-implemented interprocess shareable types (e.g.
vector, list, etc.) derive from "enable_shared_from_this" so I could just call
the shared_from_this on the retrieved raw pointer to retrieve the shared_ptr
that will be guaranteed to share the "shared_count".
None of the above yielded the desired results.
I didn't find (by googling) anybody talking about the process of creating a
shared_ptr (using the helper method of "make_managed_shared_ptr") across the
process so I assume that probably is clear and is able to achieve the mentioned
results and I must be missing something awfully obvious.
Can somebody please advise on how to achieve this?
I am loath to just jump and implement my version of "make_managed_shared_ptr"
unless I really have to and I'm sure it's designed to work across the
processes.
Thanks a in advance for help and guidance.
Kind regards
gxl
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net