ILE C/C++ Programmer's Guide


Template Instantiation Management Options

The best way to instantiate templates depends on the programming environment and the capabilities of the programmer. Table 30 lists the template instantiation options and describes advantages and disadvantages of each.

Note:
Any attempt to use both the TEMPLATE(*TEMPINC) and TMPLREG options of the Create C++ Module (CRTCPPMOD) command at the same time halts compilation.

Table 30. Template Instantiation Management Options

CRTCPPMOD Option Advantages Disadvantages
ILE C++ Default: TEMPLATE(*NONE) TMPLREG(*NONE)

You do not need to restructure code or file structure

In a network environment, you avoid potential file identification problems associated with the ILE C++ TEMPINC option.

In a team environment, you avoid file sharing problems associated with the ILE C++ TEMPINC option.

In a mixed IFS/Data Management environment, you avoid file system dependency problems associated with the ILE C++ TEMPINC option.

The time required to compile and link an entire application might be dramatically increased because:

  • The compiler has to instantiate every instance it sees.
  • Multiple instantiations could be encountered across the application, which forces the linker to throw away all but one.

If you make any change to the implementation of a template, you must recompile every unit that uses the template.

To avoid multiple template definitions, you must manually structure the code so that a single definition is generated for each template class function or static data member. To do this:

  • You must understand how the ILE C++ compiler reacts to templates.
  • You must be aware of all the template instantiations that are required by the program.
  • You might need to reorganize source files and create new compilation units.

ILE C++ Template Registry: CRTCPPMOD TEMPLATE(*NONE) TMPLREG(*DFT)
or
CRTCPPMOD TEMPLATE(*NONE) TMPLREG('path-name')

One template instantiation per application is guaranteed.

You do not need to structure programs for automatic instantiation.

Minimal manual intervention is required.

You might need to manually recompile dependent files whenever a template insantiation is removed.

ILE C++ TEMPINC option: CRTCPPMOD TEMPLATE(*TEMPINC) TMPLREG(*NONE)
or
CRTCPPMOD
TEMPLATE('path-name') TMPLREG(*NONE)

One template instantiation per application is guaranteed.

You avoid the longer compilation times that result from using the default.

You do not have to recompile all units that use a template whenever that template implementation is changed.

You need to split into separate files implementation of the following:

  • function templates
  • member functions
  • static data members of class templates

This option might not be practical in a team programming environment because:

  • The compiler might update source files while they are being modified by somebody else.
  • Source file modifications might not be file-system-independent. For example, header files that are locally available might be included rather than header files that are available on a network.


[ Top of Page | Previous Page | Next Page | Table of Contents ]