Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-01-13 02:21:07


Robert Ramey wrote:

> >> struct A
> >> {
> >> int* content;
> >> int size;
> >>
> >> template<class A>
> >> void serialize(A& a, unsigned version)
> >> {
> >> a & size;
> >> a & make_binary_object(content, size*sizeof(int));
> >> }
> >> };
> >

> This is a question of motivation, intent and utility.
>
> a) motivation - I needed a method for save/loading raw bnary data.
> the save_binary/load_binary fill this need but I found I had two
> annoying features.
> 1) The above would have to use split

Right, that's annoying.

> 2) There was no way to specify an nvp wrapper.

That's no good, either. However, the above has problems which make it
half-a-solution, IMO.

First, the above code won't compile with gcc. One needs:

                 boost::serialization::binary_object bo =
                 boost::serialization::make_binary_object(content,
                                                          sizeof(content));
                 a & bo;

That's not convenient, but I think some solution can be found. But, second,
the above code crashes. I attach a complete example. That's my primary
problem with make_binary_object. An example which looks nice (and probably
look nice even to you), crashes.

It won't crash if you either
1. Allocate the memory yourself (in which case you need split)
2. Restore a member variable.

If make_binary_object can be reliable used only for the second, then probably
it should be called 'make_pod_object'? And should not take the size at all?

- Volodya




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