Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] How do I make boost::serializationwork with std::shared_ptr?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2013-09-29 19:22:38

On Sun, Sep 29, 2013 at 3:58 PM, Arman Schwarz <armanschwarz_at_[hidden]> wrote:
> On Mon, Sep 30, 2013 at 6:48 AM, Robert Ramey <ramey_at_[hidden]> wrote:
>> [...]
>> This was OK .... until now when we have a new shared_ptr to deal with.
>> The real solution is to enhance the serialization API so that the code
>> used for implementing boost::shared_ptr can be applied to other
>> data types which are otherwise unserializable. Unfortunately, this
>> is a non-trivial task which I have yet to get to. So for now I
>> can't offer a real solution other than suggesting one use boost
>> shared pointer rather than std::shared_ptr. I dont' know if this
>> helps - but there it is.
> No, this helps a lot. I've switched to boost::shared_ptr and everything
> seems to work.
> Reading the documentation, I didn't immediately notice that
> boost/serialization/shared_ptr.hpp was a specialization for the boost shared
> pointers, not those of the standard library. This lead to my confusion.

I remember Peter Dimov making the point that std::shared_ptr needs
serialization too, and that it is incorrect for Boost Serialization to
get special access to boost::shared_ptr. But here we are.

Also keep in mind that in the general case shared_ptr is not
serializable. For example, you can't serialize shared_ptr<int> which
was created by aliasing from a shared_ptr<foo>. In most usual cases of
course it can be serialized non-intrusively.

Emil Dotchevski
Reverge Studios, Inc.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at