Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] serializing a pointer withoutcausingobject tracking
From: Stefan Strasser (strasser_at_[hidden])
Date: 2013-04-02 17:27:56


Thanks for both your answers!
Your proposals:

> Robert Ramey wrote:
> just use the base class implementation of serialize function via
> inheritance

and

Am 02.04.2013 16:35, schrieb Guy Premont:
> template<class Archive>
> void serialize(Archive & ar, const unsigned int version)
> {
> boostVx::serialization::serialize(ar,
> static_cast<T&>(*this), version);
> }
> };

...have the problem that even though it prevents tracking the actual
object reference of type T - which might be track_selectively - never
reaches the serialization library. only a pointer of type NoTracking<T>
is passed on, which is track_never. (note: serialization::serialize()
does not call basic_oarchive::save_object())
so if the object graph stores a pointer to the root object, the root
object is serialized twice and duplicated on deserialization.
this might seem like an outlandish example, but a simple tree with nodes
that have parent pointers is one.

on the other hand, if the object reference DOES reach the serialization
library it is just like serializing the object, instead of a pointer,
and I have the problem described in my initial email (load_construct_data).

the only solution I could come up with is duplicating some
implementation details in "namespace archive" and create a
nontracking_pointer_oserializer and call basic_oarchive::save_pointer()
directly:

         A *a=new A;
         nontracking_pointer_oserializer<text_oarchive,A> pos;
         oa.save_pointer(a,&pos);

I've checked the library source code, the (current) implementation does
not store the pointer serializer, so there should be no problems with
calling it with 2 different ones for the same pointer type.
the construction of the regular pointer_oserializer is what causes
tracking with track_selectively.

please let me know if I'm missing something!

Stefan


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