Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] dynamically allocated objects andreset_object_address
From: joaquin_at_[hidden]
Date: 2008-11-19 13:13:27

Robert Ramey escribió:
> I'm aware that some problems occur when loading a map of objects
> containing other objects whose types are tracked
> or something like that. I forget the details. The problem is that when
> an object is moved and that object contains other objects which are pointed
> to by other objects, I'm speaking from memory but may
> one can get the idea ffrom that.
> I think we're talking about the same thing.

I am not entirely sure... Let me restate the issue just to be confident
I'm getting it through.
Consider this pseudocode:

  T t;
  v.push_back(t); // copy t somewhere else
  ar.reset_object_adress(&v.back(),&t); // and communicate it's been

This works fine and subsequents pointers to t, when loaded, will point
to the
its new location inside v. Now consider the variation:

  T* p;
  ar>>p; // *p is created and loaded automatically by Boost.Serialization
  v.push_back(*p); // copy *p somewhere else
  ar.reset_object_adress(&v.back(),p); // and communicate it's been

This does not seem to work: objects created automatically by
Boost.Serialization when
loaded through a pointer cannot be relocated with reset_object_address:
pointers to this object will point to the same object as p, not to the
element in v.

Having a look at the source code of Boost.Serialization
(basic_iarchive.cpp) it's
apparent that moveable_objects_recent and moveable_objects_end are updated
inside basic_iarchive::load_object, but are not inside
Of course, I don't know what the hidden implications of updating these
also in
load_pointer could be, but I'd appreciate if you could comment on this.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo

> I looked into fixing
> this but I couldn't figure out how to do it. It might be possible
> to fix if one spent more time at it (or it might not). It's not
> trivial.
> Robert Ramey
> Joaquin M Lopez Munoz wrote:
>> Hello,
>> Consider a tracked type T which is only serialized through
>> T pointers: under these circumnstances, when loading a T*
>> Boost.Serialization automatically allocates a T object for
>> the pointer to refer to. I've found out that these dynamically
>> allocated objects cannot be moved by using reset_object_address:
>> this member function simply ignores them.
>> Would it be possible that reset_object_address also took care
>> of these objects or is there any limitation I'm not aware of?
>> FWIW, this is not an academic question but has raised in
>> connection with some serialization code I'm writing.
>> Thank you,
>> Joaquín M López Muñoz
>> Telefónica, Investigación y Desarrollo
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at