Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2007-09-24 11:40:27


Drew Hohmann wrote:
> I've found a few minor issues with the Boost::Serialization in VS2005.
>
> -C++ Exceptions are set to Yes (/EHsc) and the boost library isn't
> automatically detecting this. I had to manually declare _CPPUNWIND in
> the preprocessor.

Hmm - I don't understand this. Boost libraries use exceptions so
I would expect that /EHsc be always used. This is not the microsoft
default. Same goes for making wchar_t a true type rather than a short

>
> -I needed to add #pragma warning(disable:4267) to
> collections_save_imp.hpp to get rid of warnings due to unsigned int
> count = s.size(); (containers use size_t as their size, not an
> unsigned
> int. Could be trouble in 64-bit world with really large containers).

Actually, each collection type has an associated size type. E.G
std::list::size_t.
In spite of this, in the next version collection item counts will use
std::size_t.

>
> -I had to #define _SCL_SECURE_NO_WARNINGS 1 , as otherwise I get
> warning C4996 from compat_traits_type::copy(newptr, oldptr,
> prev_size); in alt_sstream_impl.hpp

Hmmm, I'm not aware of the serialization library havinng such a header file

>
> -The tutorial says to use ar &
>> boost::serialization::base_object<bus_stop>(*this); to save the base
> class. This doesn't work when saving XML, as the
>> BOOST_SERIALIZATION_NVP macro blows up because : is not a valid file
>> character. I ended up doing bus_stop |&bsbase =
>> dynamic_cast<bus_stop_corner&> (*this);
> ar & bsbase
> to save the base class.
> I'm not sure if BOOST_SERIALIZATION_NVP also has issues with a
> dereferenced pointer, as I didn't try but I suspect it may
> (BOOST_SERIALIZATION_NVP(*this)) for example.

There is a separate macro for this - I forget the name, but its in the
documentation.

>
> -In MFC serialization it is common to do the following
> bus_stop bs;
> archive << &bs;
>
> bus_stop *pbs = NULL;
> archive >> pbs
>
> the MFC CArchive automatically allocates the memory when archiving
> back
> a pointer. Using boost, I was getting no warnings, no errors, and it
> was a very difficult bug to track down because the only error I would
> get would be an exit code 3 from one of my threads. The tutorial
> should document this, and ideally boost::serialization should either
> give a
> warning or an error if the user tries to do this.

I don't see why this wouldn't work. I don't thing this should cause any
bugs or problems - other than a likely memory leak.

However, a much better way to handl the above would be

bus_stop bs;
archive << bs;
...
archive >> bs

Robert Ramey


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