|
Boost Users : |
Subject: [Boost-users] [Serialization] serialization of shared_ptr with custom deleter
From: Elizabeta (elizabeta.petreska_at_[hidden])
Date: 2015-03-26 12:17:04
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);
}
-- View this message in context: http://boost.2283326.n4.nabble.com/Serialization-serialization-of-shared-ptr-with-custom-deleter-tp4673820.html Sent from the Boost - Users mailing list archive at Nabble.com.
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