Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-10-30 12:37:54


I have one more comment about the serialization library.

I have a class with three member variables;

        unsigned resource_count;
        unsigned content_size;
        int* content;

I started writing 'serialize' method

        void serialize(Archive& ar, unsigned int version)
        {
            ar & resource_count & content_size;
            ar.write_binary(content, content_size);
        }

and realized that it won't work for input archives -- so I need to split
serialization. This looks like overkill for such a simple class. Maybe, a
better solution would be to introduce 'array' method which
- takes a pointer and the size of elements
- is defined for both input and output archieves.

        void serialize(Archive& ar, unsigned int version)
        {
            ar & resource_count & content_size;
            ar.array(content, content_size);
        }

and it will work for both input and output. (For input, the pointer need to be
created). Another solution, which is probably clearer, it to define a wrapper
class c_array, which takes pointer and a size and does the right thing. I'd
write:

      ar & c_array(content, content_size);

Surely, it's not 100% required, but would be nice.

- Volodya


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