Boost logo

Boost Users :

Subject: Re: [Boost-users] serialization
From: Robert Ramey (ramey_at_[hidden])
Date: 2013-01-29 15:40:49


Larry E. Ramey wrote:
> I'm having some trouble with the portable_binary_archive. When we
> serialze our classes via the text archive, they go in and out just
> fine. My simple test cases work great with the
> portable_binary_archive. However, in our production code, I get an
> input stream error exception tossed when I try to read a class that
> has STL elements in it.
>
> I have tried reordering includes and making sure the
> boost/serialization/list.hpp or whatever comes in front of the STL
> list class.

This shouldn't be necessary as boost/serialization/list.hpp includes
<list>

>Heck, I even put all those includes as the very 1st line
> of my test program to make sure they were included 1st. I am at a
> loss as the exception really doesn't tell me much, and the only thing
> I could figur e out is that reordering the includes did in fact fix a
> few of these exceptions.

This is red flag. The following should be true:

a) you should only need include those headers which you use
directly. Any other needed headers should be included
automatically.

b) The order of the headers shouldn't matter.

If you have a test case for which either of the above is false
(for library headers - not your own), let us know as we would
like to fix it.

If you have cases for which the above is false for any of your
own headers, I would recommed that you correct this. It will
make your life much easier.

> Any ideas? I'd post the code, but it is very intertwined and
> difficult to distill a clean example. (and my stupid trail test does
> in fact work)

This is likely a case where the save output isn't compatible with
the load input. Here are a couple of suggestions.

a) change your code to prefer ar & to ar >> and ar << whenever
possible. This diminishes possible asymetries.

b) Double check all those case where you're not using ar & but
rather ar >> and ar <<. These cases might be asymetical.

c) add NVP(name) to your code so you can save/load your classes
to xml_?archive. Since xml archives have end tags after every datatype
each datatype is checked as it's loaded in. Of course this takes
a lot of extra time and space so I only use this for debugging.
When I switch to non-xml archives the extra overhead goes away
so I just leave it in. If I do this, murphies law guarentees that I
won't actually every have to use the xml_archive, which in turn
implies that I will never have problems.

Robert Ramey

p.s. I presume we're related somehow.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net