-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: Friday, April 27, 2007 9:47 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [Serialization] Multiple BOOST_CLASS_EXPORT
Sohail Somani wrote:
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert
If you have BOOST_CLASS_EXPORT in a header file, doesn't that cause the same problems? If this is what your checkins would fix, then that's understandable.
No - code is only instatiated for archives actually used. So if the usage of an archive is confined to ONE module there are no problems. But this requires instatiating the serialization functions not in the header - that is in "out of line" code. Its quite doable but somewhat annoying. This is a result of the C++ instantiation model. Note that different compilers and linkers do things differently, but I believe that this method works on all of them.
Downside you have to explictly instantiate combination of type/archive you might export. So I recommend putting them in a library and linking against that so you don't suffer from code bloat.
Well the way I work is I define the class in the hpp file with template<typename Archive> void serialize(...); Then in the cpp file I do (something like): #include "myclass.hpp" #include "all_my_archives.hpp" #include "export.hpp" template<typename Archive> void MyClass::serialize(...){...} BOOST_CLASS_EXPORT(MyClass); So I think I'm already doing what you suggest as all my classes get compiled once into a single library.
Finally, you can also use the polymorphic version of the archive. This permits you to compile only one instantiation for all archive types. Linking is accomplished at runtime via a virtual function interface.
In time, I think I will do that. Had some issues when I tried to do it earlier but didn't bother to figure them out as I only need a single archive type. Thanks, Sohail