Boost logo

Boost :

Subject: Re: [boost] [serialization] In-memory archive?
From: Ling Li (liling_at_[hidden])
Date: 2008-10-17 13:10:52

On Fri, Oct 17, 2008 at 12:42 PM, troy d. straszheim
<troy_at_[hidden]> wrote:
> Ling Li wrote:
>> Thanks! Using streambuffer or std::istringstream/std::ostringstream is
>> indeed very convenient.
>> Has anyone thought about introducing default values in serialization
>> to save the storage size (or the number of bits tranferred over
>> network)? I hacked NVP and make_nvp to support this as an optional
>> feature, and it works fine for me. If that sounds something might be
>> useful to others, I can paste the patch here.
> You can get these numbers by making a filter device that counts bytes,
> (iirc there is an example in iostreams)
> or by serializing to, say, a vector<char> via via one of the iostreams
> push_back devices and getting the container's size after the archive is
> closed.
> Serializing to a vector is also convenient if you want to, say, use
> boost::crc
> to take and transmit checksums with the data.
> -t

Sorry that I didn't make myself clear. I meant to reduce the archive
size (not count the size). For example, in demo_gps.hpp, instead of
   ar & boost::serialization::make_nvp("hour", hour)
one might want to use
   ar & boost::serialization::make_nvp("hour", hour, 11)
so that if the hour is 11, it is not serialized in the archive. During
deserialization, if the hour is missing in the archive, 11 will be the
default value.

I have to say this can only be applied to archives with names, e.g.,
XML. And one can't use default values for elements in a vector unless
we give each element a name (e.g., the index). So compared to using
the binary archive, it might not be a save in archive size.

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