Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2002-11-19 02:09:13


On Tuesday, November 19, 2002, at 04:32 AM, Robert Ramey wrote:

> Date: Mon, 18 Nov 2002 08:19:28 +0100
> From: Matthias Troyer
>>> overriding the very general template definiations above for this
>>> special case would result in
>>>
>>> template<class T>
>>> inline boost::basic_iarchive & operator>>(boost::basic_iarchive &ar,
>>> double & x[]){
>>> ar.read_binary(x, sizeof(x));
>>> }
>>> template<class T>
>>> inline boost::basic_oarchive & operator<<(boost::basic_oarchive &ar,
>>> const T &t){
>>> ar.write_binary(x, sizeof(x));
>>> }
>>>
>>> this skips the whole serialization system and just blasts the data
>>> in/out
>
>> No, that is not what I meant. I want to optimize reading/writing of a
>> std::vector<double> for SOME types of archives only for which an
>> optimized save/load is possible. That is e.g. not for a text or XML
>> archive but only for binary archives. In your proposal this could only
>> be done by a run time type check, a dynamic_cast to a derived
>> optimized
>> class and then calling a member function of that derived class. This
>> is
>> much more naturally done through additional virtual function for
>> writing arrays of primitive data types.
>
> suppose you had a header:
>
> matias_superfast_binary_archive.hpp
>
> that contained:
>
> #include <boost/serialization/archive.hpp>
>
> template<class T>
> inline boost::basic_iarchive & operator>>(boost::basic_iarchive &ar,
> double & x[]){
> ar.read_binary(x, sizeof(x));
> }
> template<class T>
> inline boost::basic_oarchive & operator<<(boost::basic_oarchive &ar,
> const T &t){
> ar.write_binary(x, sizeof(x));
> }
>
> endof file
>
> wouldn't that do the job? the onlything is that you couldn't include
> two
> different kinds of archives in the same code module.

Exactly, I need more than one type of archive in the same code, some of
which do contain optimized functions for C-style arrays and other
contiguous homgoneneous data, and others which don't. The only solution
which comes to my mind is additional virtual functions for writing
blocks of primitive types, which default to just calling the operator<<
(>>) n times, but can be overridden by optimized functions for those
archive types where optimized writes (load) are possible. Nothing else
would need to be changed. What is objectionable in that approach?

Matthias


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