|
Boost Users : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2004-12-08 12:23:17
As can be seen, using a DLL can raise issues about repeated code in the
executable and DLL. I don't think that this is a problem unique to
serialization its just that its harder to avoid because once you start using
serialization for one thing, its going to spread to all your classes.
I believe that the C1204 error is the result of the compiler complaining
that there's just too much template instantiation and its too deep.
serialization uses a lot of mpl and uses to a deep level of instantiation.
This makes the serialization cover all the combinations of cases and traits
but can severely impact compile times. This is a problem on more than one
compiler. GCC starts to use incredible amounts of memory. VC 7.1 starts to
howl in protest.
Furthermore, in your case, the stuff is getting added to both the DLL and
the executable - thereby defeating the whole appeal of using a DLL in the
first place.
Fortunately, there is a way to deal with it.
Using the demo_pimpl example as a guide. Divide your code so that the
modules that invoke serialization are separate from the program as a whole.
If you have a lot of large classes. You might already have your classes
separated into modules by class. These classes can be compiled separatly
and added to your own application specific DLL or static library. There are
more compilations but they are pleny fast.
Now when you build your "final" executable, it will have no serializaton
code (maybe not even and class specific) code in it (except for inline
functions). it will not include any of your class serialization code. It
will include the code from the serialization library which is common and
generated for your specific classes.
link together the whole thing (either static or dynamic) and let her rip.
The key to all of this is the demo_pimpl example which shows how to contain
all class specific code in a separate module rather than in the calling
function.
Good Luck.
Robert Ramey
"Florian Preknya" <mata_at_[hidden]> wrote in message
news:41B6C3DE.8090205_at_artelecom.net...
> Hello,
> I am trying to use the boost serialization library to serialize the
> classes from my application (I use Microsoft Visual C++ 7.1 compiler).
> The most of the classes are placed in a DLL, some are in my executable
> project. For this, I had to link (statically) the DLL and the executable
> with boost serialization library. I used the BOOST_CLASS_EXPORT macro
> for all the derived classes that I serialize through a base class
> pointer: in each header, after the class declaration, I added the
> BOOST_CLASS_EXPORT(class_name) line.
>
> The DLL and executable compilation time increased drastically, and both
> the DLL and the executable export tables contain all the entities
> (classes & functions) resulted from the BOOST_CLASS_EXPORT macro
> expansion (and because the BOOST_DLLEXPORT is defined as
> __declspec(dllexport) in force_include.hpp). This happens because I have
> to include the header files from the DLL source files, also from the
> executable project source files.
> My question is: where should I put the BOOST_CLASS_EXPORT declarations
> for the DLL classes? Note that I invoke the
> serialization/deserialization only from the executable (not from the
> DLL). I tried to group all the BOOST_CLASS_EXPORT declarations in a cpp
> file in the executable project. It went pretty good, but after inserting
> many declarations, I received the C1204 error (internal structure
> overflow).
> Are there "things to know" for using the serialization library from a
> DLL? Also, there are no test projects that cover this aspect.
>
> Thanks a lot,
> Florian Preknya
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