[serialization] My implementation of serialization of STL iterators.
I succeeded in writing code that successfully serializes
my data structures, which contain a LOT a iterators, and
even vectors of iterators.
However, the end result turned out to be extremely slow
(it takes several minutes), due to some inefficiency in
boost::serialization (it should be possible to serialize
this in a few seconds). I didn't investigate why
boost::serialization becomes so slow, but I suppose it
is caused by the fact that as a result of how things
are serialized, the structure written to file is several
thousands of levels deep (meaning, that in the XML file
the indentation of the output is also many thousands of
I'm going to approach my problem of serialization in a
different way now - making a copy of the data structure,
such that the result can be serialized without needing
to serialize iterators.
Nevertheless, I don't want to keep my solution for the
iterators from others; so below follows a brief overview
of what I made.
An average serialize() function looks as follows:
void Data::serialize(Archive& ar, unsigned int const)
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(BaseClass);
ar & BOOST_SERIALIZATION_NVP(M_variable);
ar & BOOST_SERIALIZATION_ITERATOR_NVP(container, M_iterator);
ar & BOOST_SERIALIZATION_ITERATOR_NVP(container, M_vector_of_iterators);
where BOOST_SERIALIZATION_ITERATOR_NVP is my invention ;).
'container' has to be the container that the iterator(s)
point at. In the case of a vector of iterators, that is the
container that the iterators point at, not the vector.
Ie, M_iterator could of type std::set<FooBar>::iterator, then
container is the std::set<FooBar> container, and M_vector_of_iterators
would be of type std::vector<std::set<FooBar>::iterator>.
Both, the container type (std::set<FooBar>) as well as the
type of it's elements need to be tracked; hence, the above