lazy facet instantiation
Howard Hinnant
hhinnant@apple.com
Tue Nov 15 19:02:00 GMT 2005
Has the locale implementation technique of "lazy facet instantiation"
been kicked around? I searched the archive but came up empty. Imho
this is a critical technique for reducing the code size triggered by
casual use of C++ I/O.
The basic idea is that has_facet and use_facet are rigged to
recognize "required" facets. For example if has_facet is called for
a "required facet", it just answers true without checking (and that's
a compile-time-if which checks if the facet is standard, so there is
very little code generated. Similarly use_facet is specialized on
this "required facet" tag, checks the locale to see if it exists, and
if the facet doesn't, just adds it on the spot. The big advantage
here is that a facet never gets instantiated unless client code
specifically calls:
use_facet<some_standard_facet>(loc);
The default locale ctor does nothing - adds no facets, not even
instantiates them.
For example, uses of the message, money, collate and time facets are
rare. Why pay for them if you don't use them?
My apologies in advance if I've simply misunderstood the current
implementation.
-Howard
More information about the Libstdc++
mailing list