|
Boost Users : |
Subject: Re: [Boost-users] [serialization] Polymorphic serialization withpolymorphic archives problem...
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-02-24 11:55:47
Martin Lederhilger wrote:
> Hello Robert, hello Bogdan,
>
> I have quite the same problem (Exception multiple_code_instantiation
> thrown in basic_serializer_map.cpp at line 48) as Bogdan. It can be
> reproduced by changing
> the pointer type from polymorphic_base to polymorphic_derived2 in the
> original test_dll_exported.cpp example, which comes with the library.
>
> void save_exported(const char *testfile)
> {
> test_ostream os(testfile, TEST_STREAM_FLAGS);
> test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
>
> polymorphic_base *rb1 = new polymorphic_derived1;
> polymorphic_derived2 *rb2 = new polymorphic_derived2;
>
> // export will permit correct serialization
> // through a pointer to a base class
> oa << BOOST_SERIALIZATION_NVP(rb1);
> oa << BOOST_SERIALIZATION_NVP(rb2);
>
> delete rb1;
> delete rb2;
> }
>
> I think the problem is that when oa << BOOST_SERIALIZATION_NVP(rb2);
> is called, that the system registers an type in oserializer.hpp, which
> leads to creation of the singletons also in the executeable.
Ahhhh - a very useful hint. So the rule would be that if a class
is polymorphic is to be serialized through a pointer, it should ONLY
be done through a base class pointer? That is, if ALL polymorphic
base classes are abstract - this problem will never occur?
I'll have to think about this.
> I have this problem when serializing a shared_ptr<A> in class B in
> B.dll to an object of class A in A.dll.
>
> I tried to simply comment out this check, but it seems that I get
> problems with tracking later. I have a class hierarchy like this:
> C derives from B derives from A. A has a weak_ptr<A> to itself
> (something like boost::enable_shared_from_this). If I serialize an
> object of type C via a base pointer of type B the serialization walks
> like this: C::serialize, B::serialize, A::serialize, and again
> C::serialize (with a wrong this pointer - and it should not do that).
Hmmm - why should it not do that? You may have a cycle - but
the library handles that. Seems unrelated to the other problem.
> Maybe my second problem depends on the first one. I hope that my
> report can be of help.
>
> Thanks in advance for your answers,
And thanks for your useful information.
> Martin Lederhilger
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