Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-05-04 11:08:35


Brian Braatz wrote:

> Question- I was just looking for clarification. Does the boost
> serialization library allow me to have objects on different platforms
> stream to each other?

Yes.

However, the archive must be designed to be platform independent. This is a
little bit more subtle than it would first appear. For example, consider
the text archive. It stores all numbers as text delimited by spaces.
That's portable. But suppose a machine which uses an 80 bit IEEE double
stores a high precision value to an archive. Another machine that reads the
archive might only have a 64 bit double. So, some of the original precision
would be lost. Of course the original value would have been preserved to
the extent possible on the new machine. Even here, moving to an ebcdic
machine would require a custom codecvt facet which is not in library. Is
this "portable"? You be the judge.

Within the limitations of the above, text and xml archives can be considered
portable.

The binary archive is really "native binary" in that it doesn't make
conversions for integer size or endianness. (It does check that the
endianness and integer size are the same on the saving and loading machines
so it might be portable between some pairs of machines). In general the
binary archive should be considered non-portable and not suitable for
archives meant to be transferred from non identical architectures.

There has been lots of interest in making an XDR and CDR archives. I really
haven't considered issues in using XDR or CDR. I don't know whether these
are just standards for encoding low level types or describe a whole
protocol. If it's the former, it would be pretty simple implement.
Otherwise, we have the problem of matching the serial representation of some
arbitrary C++ structure with some externally defined protocol. Though it
might be possible in certain cases, this is not something that the
serialization system has been designed to do.
http://lists.boost.org/MailArchives/boost/msg63695.php

The package includes a "portable" archive as a demo. It doesn't include
code for floats and longs.

The portable archive includes a lead byte for each integer indicating the
number of bytes required to hold the value. If the integer doesn't "fit" in
the loaded type, an exception is thrown. The usage of boost::uint_16 etc.
doesn't have to be explicitly considered.

I didn't have good method for handling floats and doubles across machine
architectures. Now that I have suitable code for handling portable
floats/doubles, (http://lists.boost.org/MailArchives/boost/msg63672.php), I
might think of promoting portable_binary_?archive to a first class supported
archive. It would be complete and general, but depend on the serialization
library being implemented on the "other" machine. Not an unreasonable
restriction in my view.

For those who must have CDR/XDR I have no final answer.

Robert Ramey

 


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