share_ptr serialization

In the course if making a new shared_ptr seriailzation implementation, I've come upon a question. If a shared pointer has been created with a custome deleter, how is one to determine what kind of deleter is attached without opening the implementation of shared_ptr? That is, I see no way to correctly serialize/deserialize a shared_ptr with a custom deleter from the published interface of shared_ptr. Can anyone explain how to do this? Robert Ramey

Robert Ramey wrote:
In the course if making a new shared_ptr seriailzation implementation, I've come upon a question.
If a shared pointer has been created with a custome deleter, how is one to determine what kind of deleter is attached without opening the implementation of shared_ptr? That is, I see no way to correctly serialize/deserialize a shared_ptr with a custom deleter from the published interface of shared_ptr. Can anyone explain how to do this?
A shared_ptr is (almost) opaque with respect to the deleter currently used. When a shared_ptr with a deleter is serialized, the external representation does not contain information about the deleter. Consequently, when this pointer is deserialized, the object is created with new. This mirrors raw pointer deserialization (which also does not support "custom deleters" AFAICS), except that the newly deserialized shared_ptr will destroy correctly. I haven't found this limitation to be an issue in practice.

"Robert Ramey" <ramey@rrsd.com> writes:
In the course if making a new shared_ptr seriailzation implementation, I've come upon a question.
If a shared pointer has been created with a custome deleter, how is one to determine what kind of deleter is attached without opening the implementation of shared_ptr? That is, I see no way to correctly serialize/deserialize a shared_ptr with a custom deleter from the published interface of shared_ptr. Can anyone explain how to do this?
There is a get_deleter function. That's a runtime check of course. Someone would have to register the interesting deleters with the serialization system so that it can check for those, specifically. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (3)
-
David Abrahams
-
Peter Dimov
-
Robert Ramey