10.5. Template registry: The preferred method

New in VisualAge C++ for AIX Version 6.0 compiler is the template registry method of template handling. The compiler decides which template code to instantiate by referring to and updating a template registry file as compilation occurs. This method is fast, efficient, and best of all, does not require reorganization of your template code.

10.5.1. The -qtemplateregistry option

The -qtemplateregistry option maintains, in a registry file, records of all template instantiations as they are encountered in the compilation unit, and ensures that only one instantiation of each template is generated. By default, the compiler writes to a file named templateregistry in the current directory. You may optionally specify a different registry file name with the option. However, you must use the same registry file for the entire program.

Unlike the template instantiation file method of template handling supported with the -qtempinc option, the -qtemplateregistry option does not require the template code to be structured in a certain way. The option is mutually exclusive with the -qtempinc option, and you must not use both options at the same time. Before using the -qtemplateregistry option, remove all instantiation files in the tempinc directory. Also, any existing program that compiles successfully with -qnotempinc, that is, when every reference is instantiated in every compilation unit, will compile successfully with -qtemplateregistry. In other words, there is no migration impact should you want to take advantage of this improved template handling method.

The -qtemplateregistry option works by storing template instantiation information in a registry as compilation occurs. The registry is read for each compilation, and a check is done when an instantiation is required. If the instantiation has already been seen, nothing will happen; otherwise the template will be instantiated in the object file. In either case, a record is added for each template reference to the registry to keep track of the information about use and instantiation for all compilation units.

10.5.2. The -qtemplaterecompile option

If a change to a compilation unit removes a template instantiation, recompiling only the changed source file will result in undefined symbols at link time, since other compilation units may still require the template instantiation that is now missing. This dependency information is maintained in the template registry file in the -qtemplateregistry compiles. In this case, the -qtemplaterecompile option will cause a recompilation of all source files that rely on the template.

The -qtemplaterecompile option is, by default, turned on with the -qtemplateregistry option. It manages dependencies among compilation units, and ensures that affected source files are recompiled automatically by consulting the template registry file. It requires that object files originally generated with the -qtemplateregistry option remain in the same directory. Should you need to disable automatic recompilation for any reason, specify the -qnotemplaterecompile option. This may be the case, for example, if your build process moves the generated object files to a different directory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset