Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-09-29 11:14:30


Darren Cook wrote:

>> Or you might try the following (non-portable) idea
>>
>> ar & BOOST_SERIALIZATION_NVP(
>> make_binary_object(str, (p - str)* sizeof(int))
>> );

>Thanks, that is closest to what I was after; I don't need a portable
>version here.

>> But really, I think you might be best off replacing the class above
>> with
>>
>> class Example {
>> std::slist<int> str; // or maybe std::vector<int> str }

>It was done using a fixed size buffer to avoid dynamic memory allocation
>(mainly for speed reasons).

>However as I worked through the class some more I found it can output a
>string representation, which uses fewer bytes. So in future I might add a
>parser for input and then switch to using that (though I'll be back to
>needing separate load/save functions then won't I, oh well :-).

A couple final observations:

a) the make_binary .. implementation is maximal speed on a binary archive.
It just streams the bytes to the i/o buffer.

b) If you're concerned about binary portability and file size, take a look
at the demo binary portable. It implements saving/loading of integers as
variable length binary bytes so that a lot of the zeros are eliminated.

c) if you're concerned about file size. You might consider using the streams
library - currently pending review - to compress/de-compress the i/o on the
fly as the data is saved/loaded.

Robert Ramey


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