Boost logo

Boost Users :

Subject: Re: [Boost-users] Serializing handles to opaque objects
From: Robert Ramey (ramey_at_[hidden])
Date: 2011-10-28 02:09:30


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


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