[Insight-developers] Explicit instantiation

Brad King brad.king at kitware.com
Fri Apr 21 09:46:06 EDT 2006


Miller, James V (GE, Research) wrote:
> We've noticed code being checked into ITK to support explicit 
> instantiation.
> 
> Can someone put a page on the ITK proposals wiki page that details the 
> proposed methodology?

Sure.  I was planning to do this next week.

> It looks like there are a collection of macros and nested include files 
> to indicate what needs to be instantiated.
> 
> Looking at the macros being introduced, I fear that our developers will 
> not know how to write the necessary macro for a new class they are 
> introducing.  Do we need to use macros at all?  Is it possible to just 
> type out the instantiations we want?  I assume the macros are meant to 
> simply the export/import syntax.

Users need only write one macro per template for which explicit 
instantiations are to be used.  I plan to include extensive examples in 
the documentation to help users write them.  The macros are necessary 
for making sure that everything exported is imported properly, and to do 
imports in a cross-platform way.

> There seems to be a lot of files. Very nested. I fear it will be hard 
> for people to navigate.

There is simply one .cxx and one .h per instantiation.  This is just as 
if each instantiation were its own class, which from the compiler's 
point of view is the case.

There is also one extra .h file per template, but its purpose is 
actually to simplify the code.  We could just have itkImage.h include 
all the Templates/itkImage*.h instantiation import headers, but I 
created the extra Templates/itkImage+-.h as an intermediate step so that 
we can switch to generating the instantiations later without modifying 
itkImage.h.

> Also, it appears that we are using a one-file-per-instantiation model. 
> Is this the best approach? Or would it be better to lump a number of 
> related instantiations into one file (as long as it wouldn't get too big 
> to compile)?

See Bill Hoffman's answer for this.  This is the same reason VXL uses 
one-per-file.

-Brad


More information about the Insight-developers mailing list