Serializing handles to opaque objects
I am trying to use Boost Serialization with a set of classes which contain handles to opaque objects written in C. (Specifically, the objects are MPI communicator objects and the handles are of the MPI_Comm type, but I don't think that's important for the problem.) Now, I can easily extract the information from the objects necessary to serialize and de-serialize them; that is not the problem. The problem is that several classes have handles to the *same* object. When I restore the objects I need to make certain that all the identical handles end up pointing to the same object. I don't see an easy way to do that. The problem seems to me to be highly analogous to the (solved) problem of serializing pointers, except that the handles are not literally pointers. I'd be grateful for any advice Thanks, Jim Amundson
James Amundson wrote:
I am trying to use Boost Serialization with a set of classes which contain handles to opaque objects written in C. (Specifically, the objects are MPI communicator objects and the handles are of the MPI_Comm type, but I don't think that's important for the problem.)
Now, I can easily extract the information from the objects necessary to serialize and de-serialize them; that is not the problem. The problem is that several classes have handles to the *same* object. When I restore the objects I need to make certain that all the identical handles end up pointing to the same object. I don't see an easy way to do that. The problem seems to me to be highly analogous to the (solved) problem of serializing pointers, except that the handles are not literally pointers. I'd be grateful for any advice
This is easy to do. I'mplement serialization for your object. Use shared_ptr for your opaque handle. The smart pointer library has examples on how to do this. serialize the resulting smart pointer.
Thanks, Jim Amundson
On 10/28/2011 01:09 AM, Robert Ramey wrote:
James Amundson wrote:
I am trying to use Boost Serialization with a set of classes which contain handles to opaque objects written in C. (Specifically, the objects are MPI communicator objects and the handles are of the MPI_Comm type, but I don't think that's important for the problem.) This is easy to do.
Great. That's the kind of answer I was looking for.
I'mplement serialization for your object.
Use shared_ptr for your opaque handle. The smart pointer library has examples on how to do this.
serialize the resulting smart pointer.
Ah, I see. I was looking for a serialization-specific solution. Shared_ptr makes perfect sense. Thanks, Jim
participants (2)
-
James Amundson
-
Robert Ramey