|
Boost : |
From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2004-12-01 19:19:50
----- Mensaje original -----
De: Robert Ramey <ramey_at_[hidden]>
Fecha: Jueves, Diciembre 2, 2004 0:36 am
Asunto: [boost] Re: Re: Re: [multi_index] announce: serialization
support
> "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_ptrwhich serializes a list of pointers. In this case
> each list element is
> tracked because its a pointer. when a pointer is de-serialized a
> secondtime, 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-
> primitivetypes.
Oh, I choose std::string cause I thought it was tracked
by default, my point was meant to hold for trackable
types. So, replace std::string wit the user-defined type of
your choice and I still maintain that serialization of
foo will go wrong.
So that we don't keep discussing on thin air, please
allow me to get back to you tomorrow with a complete,
compiled example of what I mean. If in the meantime
you do the check yourself please tell me what you
come up with.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk