Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2002-11-17 22:46:03

From: Matthias Troyer <troyer_at_[hidden]>

>I believe we all agree that portable binary archive formats are
>essential in addition to the text based one.

I will be very curious to see timings on this. There is no apriori reason to know
that the translation from native types <-> XDR is faster than native types <-> text
It may well be very platform dependent.

>This discussion started because I asked you, why you don't consider
>using int8_t, int16_t, int32_t in addition to int64_t as the primitive
>types? That would make implementing a portable binary archive MUCH

int8_t, int16_t, int32_t are not C++ primitive types int64_t is (in some
versions of C++) . The function of basic_[i|o]archive is to render
all C++ primitive types as a sequence of bytes and vice versa.
int8_t etc are just typedefed pseudonyms for other standard C++
primitive types so they are already included.

> Will someone please write and submit a derivative that stores the data
> using XDR?

>Ill do that immediately, once the code compiles with g++ v3.x .

I know that others have used g++ 3.1 with only a couple of minor
problems. When advised of these, I made changes to accommodate
them. Also it compiles clean with gcc 2.95 so I would be very surprised
if there is a problem wit g++ 3.x. I did get one report of problems but
more information was required. Please let me know of any compile
errors with this platform. Also all the tests and demos should run.
No one test/demo covers everything. Also I will try with MSVC 6
in the next few days and resolve that issue.

> template<class T>
> inline boost::basic_iarchive & operator>>(boost::basic_iarchive &ar, T
> &t){
> ...

>I am confused by that answer. Could you please elaborate?

The main syntatical mechanism for appending, extracting a data item from an archive

ar << data;


ar >> data.

These are realized with the following two templates:

template<class T>
inline boost::basic_iarchive & operator>>(boost::basic_iarchive &ar, T &t){
template<class T>
inline boost::basic_iarchive & operator>>(boost::basic_iarchive &ar, T &t){

which are coded to handle all types of data types, pointers, arrays, enums, etc....and
invoke the lower level functions/templates that handle nested types and structures.

Now suppose your only consideration is to minimize the time required to save/load an array
of doubles. Protability and text readability is of no concern in this example.

overriding the very general template definiations above for this special case would result in

template<class T>
inline boost::basic_iarchive & operator>>(boost::basic_iarchive &ar, double & x[]){
        ar.read_binary(x, sizeof(x));
template<class T>
inline boost::basic_oarchive & operator<<(boost::basic_oarchive &ar, const T &t){
        ar.write_binary(x, sizeof(x));

this skips the whole serialization system and just blasts the data in/out

Robert Ramey

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