Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-01-09 10:03:55

I've got a problem with the serialization library on my project. The docs for
version 14 say say saving binary objects should be done with
'make_binary_object'. Unfortunately, it does not work for the following case:

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

Upon loading, the serialization lib tries to load 'size*sizeof(int)' of data
into 'content', but the problem is that neither 'size' nor 'content' is
initialized at the time. So, it loads random amount of data to random memory
location. What's worse, 'write_binary' and 'read_binary' member functions has
disappeared from archives.

So, my questions are:

1. How do I read binary manually?
2. Isn't make_binary_object too easy to use incorrectly? In fact, the only way
how it can be used is when size if constant and data is part of object. In
all other cases, you need to do dynamic allocation yourself, and after that,
you don't need 'make_binary_object', you can just read the data given that
there's answer to question 1 above.
3. Is it possible to either modify make_binary_object or introduce a new
function which will do new[] on loading and restore data size as well?

- Volodya

Boost list run by bdawes at, gregod at, cpdaniel at, john at