Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-06-27 01:17:36


David Abrahams wrote:

> Vladimir Prus <ghost_at_[hidden]> writes:
>
>> >
>> > Its very easy to write
>> > for(...{
>> > X x = *it; // create a copy of
>> > ar << x
>> > }
>> >
>> > all the x's are at the same address so if they happen to be tracked
>> > because
>> > a pointer to some X in serialized somewhere in the program, then the
>> > subsequent copies would be supprsed by tracking.
>>
>> What does "the subsequence copies would be supressed by tracking"? Are
>> you saing that only one 'X' will be stored in archive?
>
> Yes, if (as is highly likely) the x happens to have the same address
> in each iteration of the loop. To reconstruct object graphs correctly
> (that's what tracking is for), you need to do it that way.

If you serializing object graphs, then you either:

1. Always store an object by pointer
2. Save it by value first time, and by pointer other times.

Both situations are easy to detect. But another situation is when object
with the same address is saved several times by value. In that case, it's
very reasonable to do no tracking at all.

Implementing should be easy. For each stored pointer it's necessary to keep
a flag, telling if:

   - there was one save by value
   - there were several saved by value
   - there were save by pointer.

The logic is.

  - Save by value
         - if there were saves by pointer, throw pointer_conflict
         - if there were (several) saves by value,
           save the data, change flag to "several saves by value"

  - Save by pointer
         - if there were save by value, store id of previously saved object,
           change flag to "save by pointer"
         - if there were several saves by value, throw something
         - if there were save by pointer, store id of previously saved
           object

I can't find anything wrong with above logic. Of course, I might be missing
something too.

- Volodya


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