|Skip Navigation Links|
|Exit Print View|
|Oracle Solaris Studio 12.3: C++ User's Guide Oracle Solaris Studio 12.3 Information Library|
The template repository stores template instances between separate compilations so that template instances are compiled only when necessary. The template repository contains all nonsource files needed for template instantiation when using the external instances method. The repository is not used for other kinds of instances.
The cache directory is contained within the directory in which the object files are placed. You can change the name of the cache directory by setting the SUNWS_CACHE_NAME environment variable. Note that the value of the SUNWS_CACHE_NAME variable must be a directory name and not a path name. The compiler automatically places the template cache directory under the object file directory so the compiler already has a path.
When the compiler must store template instances, it stores them within the template repository corresponding to the output file. For example, the following command writes the object file to ./sub/a.o and writes template instances into the repository contained within ./sub/SunWS_cache. If the cache directory does not exist and the compiler needs to instantiate a template, the compiler will create the directory.
example% CC -o sub/a.o a.cc
The compiler reads from the template repositories corresponding to the object files that it reads. For example, the following command reads from ./sub1/SunWS_cache and ./sub2/SunWS_cache, and, if necessary, writes to ./SunWS_cache.
example% CC sub1/a.o sub2/b.o
Templates that are within a repository must not violate the one-definition rule of the ISO C++ standard. That is, a template must have the same source in all uses of the template. Violating this rule produces undefined behavior.
The simplest, though most conservative, way to ensure that the rule is not violated is to build only one program or library within any one directory. Two unrelated programs might use the same type name or external name to mean different things. If the programs share a template repository, template definitions could conflict, thus yielding unpredictable results.
In addition, the template repository tracks changes in your compilation. For example, if you have the -DDEBUG flag set to define the name DEBUG, the database tracks this. If you omit this flag on a subsequent compile, the compiler reinstantiates those templates on which this dependency is set.
Note - If you remove the source code of a template or stop using a template, instances of the template remain in the cache. If you change the signature of a function template, instances using the old signature remain in the cache. If you run into unexpected behavior at compile or link time due to these issues, clear the template cache and rebuild the program.