Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-04-12 10:55:42


John Maddock wrote:

> Boost.Regex avoids this by moving most of the template instances you
> will likely use into the library (so they don't get instantiated in
> your object files), and precompiled headers are certainly a big win
> in this case.

FWIW - this is the approach used by the serialization library. All
"known" instantiations are built and added to the library. The linker
just adds in the appropriate instantiation. The permits things like
xml serialization (which depends upon spirit) to be used without
constantly recompiling this code every time that archive is used.

But still if one serializes a lot of class types, it can take a while. So
the recommended approach is to divide one's code into smaller
modules that don't have to be recompiled as often.

The serialization library also includes a test/demo (demo_pimpl)
which illustrates how to do this with one's own serialization. In fact,
I find it useful to explicitly instantiate all the combinations I might use
and add them to an "application library". The final application link
draws from this library only the instantiations actually use.

To summarize - in theory one can just include headers willy-nilly
and let the compiler-linker handle everything. In practice, there
is a lot of benefit to investing some effort to divide one's
application into smaller modules each with fewer dependencies.

That's my advice.

Robert Ramey


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