Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-04-13 23:42:28

Matthias Troyer wrote:

> After a few tweaks - which I will report later - I got serialization to
> compile on my installation of MacOS X.

That is very good news - it's a platform I never tried. Please try and run
the bjam test suite as well.

> I have a question that does not seem to be addressed in the
> documentation: What is the difference betweem save and save_override or >
> load and load_override?

> demo_fast_binary_archive.cpp uses save_override and load_override but I
> could not find it documented?

Making a new archive class is described in the section "New Archives -
Implementation". The model for an archive class is:

// class trivial_iarchive - read serialized objects from a input text stream
class trivial_iarchive

: public boost::archive::common_iarchive<trivial_iarchive>
    // permit serialization system priledged access to permit
    // implementation of inline templates for maximum speed.
    friend class boost::serialization::load_access;

    // member template for loading primitive types.
    // Override for any types/templates that special treatment
    template<class T>
    void load(T & t);

    // public interface used by programs that use the
    // serialization library

    // the >> operator
    template<class T>
    trivial_iarchive & operator>>(T & t){
        boost::serialization::load(* This(), t);
        return * This();

    // archives are expected to support this function
    void load_binary(void *address, size_t count);


So in theory one has to implement the two undefined functions.

For each primitive data type, int, float, etc. or any type designated as
primitive define a "load" template for function to read them from the file.

For each data type that you want to treat specially - rather than allowing
the serialization library to do the job - define an overload for the >>

That should be all there is too it.

The archive classes included in the library are much more elaborate for a
number of reasons. Among others these are:

a) portability to platforms which fail to support Partial Template Function
Ordering. This is what make the load_override functions necessary so that
we can apply the "extra argument" work around to simulate PTFO for these
platforms. They are not part of an public interface but rather internal
artifacts of the implementation of these archives.

b) the desire that the archives be templates so that they could work with
both char and wchar_t i/o

c) the desire to factor out common code for text primitives so that it
wouldn't have to be duplicated for xml and text archives.

> I can implement an
> optimized archive along the lines of demo_fast_binary_archive.cpp, but
> extended to also support std::vector, std::valarray, ...

Before doing that, I would suggest making a test application with the
standard binary archive and try to get some baseline timings. I would be
curious to know the results of this.

Remember that the point of demo_fast_binary_archive.cpp isn't so much to
propose a faster archive ( though it may be ) but really to illustrate how
one might derived from one of existing archives to alter its behavior.

Robert Ramey

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