Skip to content

Commit 2f5e538

Browse files
committed
Merge pull request #35 from rob100/precompiled_header
Precompiled Header
2 parents d1064a6 + 1620934 commit 2f5e538

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

08-Considering_Performance.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ This is a general form of "Firewall Frequently Changing Header Files" and "Don't
6262

6363
### Consider using precompiled headers
6464

65+
The usage of precompiled headers can considerably reduce the compile time in large projects. Selected headers are compiled to an intermediate form (PCH files) that can be faster processed by the compiler. It is recommended to define only frequently used header that changes rarely as precompiled header (e.g. system and library headers) to achieve the compile time reduction.
66+
But you have to keep in mind, that using precompiled headers has several disadvantages:
67+
* The usage of precompiled header is not portable.
68+
* The generated PCH files are machine dependent.
69+
* The generated PCH files can be quite large.
70+
* It can break your header dependencies. Because of the precompiled headers, every file has the possibility to include every header that is marked as a precompiled header. In result it can happen, that the build fails if you disable the precompiled headers. This can be an issue if you ship something like a library. Because of this it is highly recommend to build once with precompiled header enabled and a second time without them.
71+
72+
Precompiled headers is supported by the most common compiler, like [GCC](https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html), [Clang](http://clang.llvm.org/docs/PCHInternals.html) and [Visual Studio](https://msdn.microsoft.com/en-us/library/szfdksca.aspx).
73+
Tools like [cotire](https://github.com/sakra/cotire/) (a plugin for cmake) can help you to add precompiled headers to your build system.
74+
6575
### Consider Using Tools
6676

6777
These are not meant to supersede good design

0 commit comments

Comments
 (0)