Open Source Platform
for interconnected virtual worlds

Header Usage Best Practices

From Rex community wiki

The Naali build projects extensively use Precompiled Headers feature of modern compilers to speed up compilation times. To ensure fastest possible performance, follow these guidelines:

  • In your PCH, include all commonly used 3rd party headers (Qt, Ogre, etc.)
  • The Core project contains a CoreStdIncludes.h which contains the most commonly used standard C++ includes, as well as some from boost and PoCo. Include this in your PCH.
  • If your modules tightly integrate with other Core modules and Services, also add in Foundation.h and Framework.h, unless you also modify the Core files very often.
  • Avoid including any files in the PCH that are modified often. Whenever a header in the PCH file changes, your whole project needs to be rebuilt!
  • Do not rely on the PCH to provide you with all the headers you need. Try building your module occasionally with the PCH file cleared to ascertain that it still builds without it. This makes optimizing the PCH use easier.
  • Do not include StableHeaders.h in headers!

With regards to standard C++ headers usage, try to follow these tips:

  • Try to keep all .h files thin with respect to including other header files
  • Use forward declarations where possible to avoid deep header dependencies - let the .cpp files include the headers they really need.