Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-06-27 06:15:24


Vladimir Prus <ghost_at_[hidden]> writes:

> 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.

Yes, that's a reasonable option; I think it's what Peter has been
advocating.

> 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

I'm sure you mean assert something, right? ;-)

> - 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.

It's certainly reasonable and predictable. Since the library can know
when it is dealing with a reference member and when it is dealing with
a value member, if reference members are just saved by pointer, it all
holds together.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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