Boost logo

Boost :

From: Dave Harris (brangdon_at_[hidden])
Date: 2003-10-06 04:17:58


In-Reply-To: <01C38B87.6C788770_at_[hidden]>
ramey_at_[hidden] (Robert Ramey) wrote (abridged):
> The default implementation for deserializing a pointer is:
>
> template<class Archive ar, class T>
> void load_construct(Archive & ar, T * t, unsigned int file_version)
> {
> new( pt ) T(); // Default-construct in place.
> ar >> *t; // presumably
> }
>
> I don't see the improvement. You're still stuck with giving
> load_construct access to a private constructor.

The improvement is that you can override load_construct so that it doesn't
use the default constructor, and doesn't need friend. You are not stuck
with this default implementation.

> >int f()
> >{
> > Foo x[3];
> > return x[0].value();
> >}
>
> >The array in the code snippet above does not always exist. It is
> >created when the function is entered and destroyed when it exits.
>
> Hence need not be created/constructed by the serialization system which
> is which is what is being discussed.
>
> >Elements can be constructed at will in suitably aligned raw memory,
> >and an array will be created.
>
> Serialization of the above created "array" requires no special
> consideration.

Agreed. What I had in mind was more like:
    int f( Archive &ar ) {
        fixed_array<Foo,3> x( ar );
        return x[0].value();
    }

where fixed_array<T,size> is based on:
    unsigned char data[ size * sizeof(T) ]; // with alignment.

Getting this to work is non-trivial, though.

-- Dave Harris, Nottingham, UK


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