Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] custom allocation/deletion
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-06-07 18:32:31


Brian Budge wrote:
> On Thu, Jun 7, 2012 at 9:45 AM, Robert Ramey <ramey_at_[hidden]> wrote:
> I essentially want to be able to pass contextual data
> along the entire deserialization process. With
>
> struct Bar {
> Foo *foo;
> int numFoo;
> };
>
> This could enable changing something like
>
> template <class Archive>
> void load(Archive &ar, Bar &b, const unsigned int version) {
> ar >> b.numFoo;
> b.foo = new Foo[b.numFoo];
> ar.load_binary(b.foo, b.numFoo * sizeof(Foo));
> }
>
> to
>
> template <class Archive, typename Context>
> void load(Archive &ar, Bar &b, const unsigned int version, Context
> &ctx) { ar >> b.numFoo;
> b.foo = ctx.get_buffer<Foo>(b.numFoo);
> ar.load_binary(b.foo, b.numFoo * sizeof(Foo));
> }
>
> In this case, the Context might be a buffer object pool or a set of
> pools for different types or really anything contextual. Of course
> you could do this with global objects, but if we want to keep these in
> logical allocation groups so all memory can be flushed once operation
> on a context is done, that won't work.

class A {
...
};

class A_PLUS { // includes extra data only for serialization
    const A * m_aptr; // data
    extradata m_t
    A_PLUS(const A * aptr; extradata t) :
        m_aptr(aptr),
        m_t(t)
    {}
};

main(..){
    strstream os;
    binary_oarchive oa(os);
   A a;
   A_PUSH aplus(&a, extradata);
   oa << aplus
}

Consider something like this

>
> Thanks again for your comments.
> Brian


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