[Serialization] serialization of shared_ptr with custom deleter

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Serialization] serialization of shared_ptr with custom deleter

Elizabeta
Hi
I am using boost 1.49.  There is problem with serialization of shared_ptr with custom deleter, it doesnot preserve the deleter. After deserialization of shared_ptr with custom deleter, when using boost::get_deleter on the deserialized  shared_ptr it returns null. Here is code example

struct DetachTest
{
    ~DetachTest()
    {
        int debug =0;
    }
    friend class boost::serialization::access;
    template<class Archive>
    inline void serialize(Archive & ar,            
        const unsigned int file_version)
    {
       
    }  
};

    {
        boost::shared_ptr<DetachTest> ss(new DetachTest,SmartDeleter<DetachTest>());
        std::ofstream ofs("C:\\detach.xml");
        boost::archive::xml_oarchive oa(ofs);
        oa & boost::serialization::make_nvp("detach",ss);      

    }

    {
        DetachTest* test = 0;
        boost::shared_ptr<DetachTest> ss (test,SmartDeleter<DetachTest>());
       
        //del is nonnul here
        SmartDeleter<DetachTest>* del = boost::get_deleter<SmartDeleter<DetachTest> , DetachTest>(ss);

        std::ifstream ifs("C:\\detach.xml");
        boost::archive::xml_iarchive ia(ifs);
        ia & boost::serialization::make_nvp("detach",ss);
       
        //de2 is null after deserialization
        SmartDeleter<DetachTest>* de2 = boost::get_deleter<SmartDeleter<DetachTest> , DetachTest>(ss);
    }  
Reply | Threaded
Open this post in threaded view
|

Re: [Serialization] serialization of shared_ptr with custom deleter

Robert Ramey
double check that this is not a feature of shared pointer.

Perhaps figure out a patch

open up a trac item.

Robert Ramey