Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-03-12 07:53:54


David Tonge wrote:

> I had been including the BOOST_CLASS_EXPORT(T) commands in the headers
> but that means I have to include all of the archive headers, and
> export.hpp in every header, and that makes for slow compilations. My
> hope is that I can include all of those only in the implementation .cpp
> and put the BOOST_CLASS_EXPORT(T) there. I was also worried that if I
> included the BOOST_CLASS_EXPORT(T) in the header then every other .cpp
> which included that header would also try to register the guid for T -
> surely an unnecessary replication of effort.

I actually though that we should have "polymorphic archive" -- one whose
operations are virtual. It would have a number of derived class which wrap
existing archives in a polymorphic interface.

In code:
   
   class polymorphic_archive { } :
   template<class Wrapped>
   class polymorphic_archive_wrapper {
       /// Forward everything to m_wrapper
        Wrapper& m_wrapper;
   };

The serialization of exported class would work like:
1. BOOST_CLASS_EXPORT registers the class with all #included archives *and*
with the polymorphic archive.
2. When saving, if class was registered with the used archive types,
everything works as now. Otherwise, a wrapper over archive is created and
used for saving

    polymorphic_archive_wrapper<ActualArchiveType> w(actual_archive);
    w << object;

This way, you don't need to #include archive headers before calling
BOOST_CLASS_EXPORT at all -- everything will work. It would only be needed if
you want extra efficiency. Howver, I suspect BOOST_CLASS_EXPORT has some
overhead already, so this might not be an issue.

The problem, now, is to have somebody implement polymorphic archive ;-)

> If this is the case then it's going to be quite inconvenient. It would
> mean one would have to BOOST_CLASS_EXPORT every class in every DLL where
> an instance of it (or a shared_pointer which might contain it) might be
> saved. If that were the case then I'd advocate making
> boost_serialization into a DLL, rather than a static library.

Maybe, you could try tweaking the Jamfile so that library is build as dynamic
and try your test?

- Volodya


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