Hi,
I am trying to serialize a large set of objects in our library. I am using the
Serialization library from version 1.33 with MSVC 2003. When I had all
serialization code in the header files of the classes, linking took too much
time and memory. Therefore I am now using explicit template instantiation
of the serialize function (see below) in conjunction with precompiled headers
for the Boost.Serialization.
The problem is this: When I de-serialize a DerivedObject to a BaseObject-pointer
(so that only the header of the BaseObject class is included) the linker seems
to throw away the information from the explicit template instantiation of the
DerivedObject in some cases. When I combine the explicit template instantiation
and definition of serialize into one object for BaseObject and all DerivedObject,
the linker keeps the registration information of the derived class (because MSVC
uses object-level linking). Due to the coding standards in our institution this
method was disapproved.
Is there a way to make the linker keep the registration information of
DerivedObject?
Best regards,
Markus Himmerich
.h-File:
----------------------------------------
namespace boost{
namespace serialization {
class access;
}
}
class BaseObject {
public:
...
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int /*version*/);
}
.cpp-File:
----------------------------------
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/set.hpp>
#include <boost/serialization/string.hpp> //Use precompiled headers for these headers
template<class Archive>
void BaseObject::serialize(Archive & ar, const unsigned int /*version*/)
{
ar & BOOST_SERIALIZATION_NVP(id_);
ar & BOOST_SERIALIZATION_NVP(data1_);
}
template void a::serialize<>(boost::archive::xml_iarchive & ar, const unsigned int /*version*/);
template void a::serialize<>(boost::archive::xml_oarchive & ar, const unsigned int /*version*/);
BOOST_CLASS_EXPORT(a)
BOOST_SERIALIZATION_SHARED_PTR(a)
Analogous files for DerivedObject.