Boost logo

Boost Users :

Subject: Re: [Boost-users] Using boost::serialization in real-time without allocating memory
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-09-17 08:57:41


Am Thursday 17 September 2009 16:33:16 schrieben Sie:
ting an new serialization system.
>
> Thanks for the detailed answer. I missed the point that an archive
> could serialize only once. This is indeed incompatible with my design
> requirements. By design, our serialisation requirements are PODs and
> std::vector<POD> since we only exchange 'pure' data structures (and
> use std::vector in a limited way, almost similar to array<POD>). Much
> of the features in boost::serialization aren't required for us.

PODs and POD-containers is pretty simple. just pass a type that is compatible
with boost.serialization's archive types to the container's serialize()
function.
here's part of the archive type I use for types that support this kind of
serialization. it will fail statically if the container tries to serialize
anything non-POD.

class serializer{
public:
        explicit serializer(...
        void save_binary(void const *data,std::size_t size){
                ...
        }
        template<class T>
        serializer &operator<<(T const &t){
                BOOST_STATIC_ASSERT(serialization::implementation_level<T>::value ==
serialization::primitive_type);
                ...
                return *this;
        }
        ...
        template<class T>
        serializer &operator&(T const &t){
                return this->operator<<(t);
        }
private:
        ...
};


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