[Insight-developers] Explicit instantiation

Brad King brad.king at kitware.com
Fri Apr 21 10:15:18 EDT 2006


Gaetan Lehmann wrote:
> I'm not sure to understand what the explicit instantiation does.
> It build some template specialization for a restricted set of template  
> arguments, and put this code in the ITKCommon lib ?

This is correct.

> What is the benefit ? Compilation time ? executable size ?

Both.  Right now the ITK build tree is over 7GB with all the tests and 
Tcl/Python wrapping on Linux.  Alot of the space comes because every 
object file that gets built has its own copy of implicitly instantiated 
templates like "itk::Image<unsigned char, 2>".  Most of these duplicate 
symbols are merged by the linker, which means that the compiler wasted 
time compiling them in the first place.  Even after the linker merges 
them each executable still has its own copy, even with shared libraries 
enabled.

The explicit instantiation support puts the common instantiations in one 
library ahead of time and then instructs the compiler not to build those 
instantiations elsewhere.  This should significantly reduce the disk 
space and compile time needed to build ITK with tests and wrapping.

If you look at the Code/Common/Templates directory you will see 
something that looks a bit like the wrapper configuration files.  In the 
future I plan to find a way to merge these so that all explicit 
instantiations are wrapped.  Building wrappers for them should be much 
faster because the .txx files do not need to be included at all since 
now only calls to the code need be compiled in the wrappers instead of 
the code itself in the form of implicit instantiations.

-Brad


More information about the Insight-developers mailing list