Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Serializing const* to serializeddata
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-11-06 15:36:59


Noah Roberts wrote:
> In article
> <c72e33ce0911051651le8017fes28076be7778b87f5_at_[hidden]>,
> emildotchevski_at_[hidden] says...
>>
>> On Thu, Nov 5, 2009 at 4:08 PM, Noah Roberts
>> <roberts.noah_at_[hidden]> wrote:
>>>
>>>
>>> Consider something like so:
>>>
>>> struct A
>>> {
>>> ...?
>>> };
>>>
>>> struct B
>>> {
>>> std::list<A> items;
>>> };
>>>
>>> struct C
>>> {
>>> A const* ptr_to_item_in_B_items;
>>> };
>>>
>>> Possible? Impossible?

With the possible exception of the "const" this should work fine.
In fact, the main demo included with the package and described
in the tutorial does exactly this.

For this to work, struct B would have to be serialized before
struct C. If this is not done, one will get an exception since
otherwise would endup with two copies of the original A.

Assuming we avoid this trap, the tracking facility addresses
this. As list<A> is saved, the addresses of all the A
elements are saved. When (later) C is saved, only a
reference to the original copy is saved. On loading
its the same processess in reverse.

All this happens without the programmer/user needing
to do anything special other than make sure that the
types are not "untracked". In almost all cases, the
defaults will give the behavior desired without the programmer/user
even being aware of it.

Robert Ramey


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