Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Polymorphic serializationwithpolymorphic archives problem...
From: Martin Lederhilger (ml_at_[hidden])
Date: 2010-02-25 02:13:14


Robert Ramey schrieb:
> 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.
>
>
Thanks for your answer,

in my case I want to be able to serialize an object with a pointer to
its most derived type, a pointer to it's base class,
a pointer to the base class of base class, ...

Actually this problem should happen with all
BOOST_CLASS_EXPORT_IMPLEMENTed classes
which reside in one DLL, and are serialized (+automatic register_type)
in another DLL or EXE.

Is the intention of the exception to prevent useres from using
BOOST_CLASS_EXPORT_IMPLEMENT
multiple times? If so, then the quick solution for me is to ignore the
exception (the serialisation seems to work then, but I know that a
solution for the library itself is much trickier).

Martin


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