
martin.ecker@tab.at wrote:
also the fact that a special export macro BOOST_SHARED_POINTER_EXPORT is needed to export classes used with shared_ptr. It's especially cumbersome when shared_ptr is used polymorphically, i.e. we use shared_ptr<Base> that actually points to an instance of class Derived.
Note that this should be required ONLY when shared_ptr is used polymorphically.
there should be proper, built-in support in boost::serialization for it.
agreed.
No extra macro or intrusive hack to shared_ptr should be required in order to be able to use it.
The macro described above is required to instantiate code not explicitly referred to. This occurs with the serialization of derived pointers through a polymorphic base class. There are two ways to do this: explicit registration and export. Each one has its drawbacks. The only alternative that has been suggested is to use the type_info name as a class identifier. I didn't do this as it would inhibit portability of archives across compilers and namespaces.
As was discussed before, a good way to achieve this is to use a pointer-to-shared_ptr map in the input archive when loading archives that contain shared_ptrs. This is actually the approach that we've hacked into the version of boost::serialization here at work. We've been using it for a couple of months now like this and have not experienced any problems with it.
Gee, wouldn't it have been easier just to add a friend to the share_ptr?
And it also works for serializing weak_ptr.
However, I would really appreciate an 'official' solution to shared_ptr (and weak_ptr) serialization.
Me too - but I can't see how this is going to happen Robert Ramey