DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
The Design of C++ Standard Components

Minimizing the number of static objects defined in headers

Static objects defined in header files impose a space penalty on all object files that include those headers. If the static objects are of a type that has a constructor, they also impose a runtime penalty on all object files that include those headers. Finally, statics pollute the global namespace, raising the possibility of collision with client-defined names.

Even small penalties can add up for clients with hundreds of object files in their applications. Instead of this:

       Foo.h
           ...
           static const char x;

We have attempted, wherever possible, to do the following:

       Foo.h
          ...
          class Foo {
          private:
              static const char x;
              ...
          };

Next topic: Inheritance: why we have mostly avoided it
Previous topic: Minimizing linkage dependencies

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005