Boost logo

Boost Users :

Subject: [Boost-users] [serialization] speed & size optimized binary archive
From: Sebastian Karlsson (sebastian_at_[hidden])
Date: 2009-11-18 14:48:55


I'm trying to create a binary archive which manages serialization of
derived type through base and archive versioning ( not on a type by
type basis ). Looking at the binary archive which ships with the
distribution it serializes a whole lot of things which is unnecessary
for our use case.

Going by the documentation and looking on how other archives are
implemented I've created a basic implementation, which while compiling
doesn't handle serialization of exported types. Even though the
documentation is mostly great, this is a small area which seems to be
left out, namely the requirements of an archive to be able to
serialize / deserialize exported types properly. Looking at the
provided archive types it's not clearly distinguishable exactly what's
needed for this functionality. The documentation mentions
BOOST_SERIALIZATION_REGISTER_ARCHIVE, which is used for the archive.

Also, it would be great to know more in depth what actually gets
serialized, even if it's subject of change for newer versions. For
example, I'm interested in knowing how serialization of exported types
will impact archive size. I'm thinking just an extra id per instance?
Reading the documentation I got a hunch that extra meta data on a per
type basis gets serialized to the archive as well. Under "Types used
by the serialization library" several types are mentioned, which of
these can be ignored for our use case?

This is a reduced form of the output archive which together with an
analogous input archive doesn't manage to serialize derived types
through their base even if exported, checked to work with the supplied
binary archive type.

class BinaryOArchive : public boost::archive::detail::common_oarchive<
BinaryOArchive >
{
        typedef std::ostream Sink;
        friend class boost::archive::save_access;
        template< typename Type >
        void save( Type& a_Type )
        {
                m_Out.write( reinterpret_cast< const char* >( &a_Type ), sizeof( Type ) );
        }
public:
        BinaryOArchive( Sink& a_Out ) : m_Out( a_Out ) {}
        void save_binary( void *a_Address, std::size_t a_Count )
        {
                m_Out.write( static_cast< const char* >( a_Address ), a_Count );
        }
private:
        Sink& m_Out;
};
#include "boost/archive/impl/archive_serializer_map.ipp"

BOOST_SERIALIZATION_REGISTER_ARCHIVE(Altus::BinaryOArchive)
BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(Altus::BinaryOArchive)


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