Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-12-01 18:36:29


"JOAQUIN LOPEZ MU?Z" <joaquin_at_[hidden]> wrote in message
news:206712203b1d.203b1d206712_at_tid.es...

> ----- Mensaje original -----
> De: Robert Ramey <ramey_at_[hidden]>
> Fecha: Miércoles, Diciembre 1, 2004 10:15 pm
> Asunto: [boost] Re: Re: [multi_index] announce: serialization support

> [snip]

> > If you guarentee that the container itself is always serialized
> > before your
> > indices, then de-serialization of the indices would automatically
> > be reduced
> > to providing the original (tracked) pointer. In such a case, I
> > would think
> > the whole isse would never appear and that the implementation
> > would be very
> > straight forward.
> >

> I think this is not correct (but I'd like to be
> proven wrong, that'd mean I could simplify my code.)
> Consider this:

> struct foo
> {
> std::list<std::string> cont;
> std::string* pos; // pos points to an element of cont

> private:
> friend class boost::serialization::access;

> template<class Archive>
> void serialize(Archive & ar, const unsigned int)
> {
> ar&cont; // before pos, as you suggest
> ar&pos;
> }
> };

> My thesis is that loading a foo will get it
> wrong --pos won't be pointing to an element of cont,
> but rather to some random address in stack memory.
> I'll check it out on my compiler tomorrow, but I was
> already through this when designing multi_index
> serialization. See my point now? Am I missing something?

Hmmm - let me consider this. My view is based on the test test_list_ptr
which serializes a list of pointers. In this case each list element is
tracked because its a pointer. when a pointer is de-serialized a second
time, tracking assures that the pointer is reloaded.

In your case - std::string is tracked on output. When it its serialized a
second time, only the object ID is written out. So when it is read back in
the second time, the serialization system recognizes that its a copy and
just reloads it.

This only gotcha is that most primitive types are not tracked by default.
and std::string has been assigned a serialization trait of "primitive" that
means don't track. So I believe that this would work for non-primitive
types. If you need this towork for a prmitive type (e.g. int, or...) use a
serialization wrapper.

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk