|
Boost Users : |
Subject: Re: [Boost-users] Problems with De/Serializing data structures with dll
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-07-02 11:42:26
cute example.
This has nothing to do with dlls etc. The problem is actually quite simple:
//The serialization itself
oa.register_type(static_cast<BaseImplementation *>(tmp));
for(int i=0; i < 114; i++)
{
oa << tmp;
tmp = tmp->getNext();
//oa << *tmp;
}
//oa << first;
a) Your data structure is a loooong linked list of pointers.
b) Serialization of the first pointer in the list is going to
recursively serialize all the objects in the list.
c) subsequent serialization of any previously serialized ones
will be optimized away.
If you want to do this in this way, The obvious way would
be to make sure there's enough stack space. Remember
that serialization is a recurrsive process. If you really
need to serialize an arbitrarily long linked list, you'll
have to think of another way. You might want to look
at the implementation of serialization for std::list in the
library which serializes the data but reconstructs the links
on load (using push back) rather than serializating them. This
was done not to avoid this problem but rather because
it made use of the public interface of std::list.
Robert Ramey
P.S. Usage of export often cause "weird linking errors"
do to the need to explicitly instantiate code not referred
to by name. One then has to invest some effort in thinking
about getting stuff serialized. This conflicts with the goal of the library
to permit usage of serialization by those who have a lot
of other stuff to do.
RR.
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