benefits of precompiled headers

G

Guest

Several C++ compilers now allow precompiled headers, supposedly as a
compile-time optimization.
I personally do not use them, although I code mostly in VC++ (which has
a tendency to shove PCH down your throat), because:
a. When headers are lumped together into one huge entity the code loses
a sense of who-uses-what, or so it seems to me. I like to be able to
know from the include directives of each file as much as I can about
the dependecies of that file.
b. I never noticed a significant speed advantage using PCH - although I
never actually timed and compared.

What are you opinions on the matter?
Are there any known disadvantages to using PCH?
 
I

Ivan Vecerina

Several C++ compilers now allow precompiled headers, supposedly as a
compile-time optimization.
I personally do not use them, although I code mostly in VC++ (which has
a tendency to shove PCH down your throat), because:
a. When headers are lumped together into one huge entity the code loses
a sense of who-uses-what, or so it seems to me. I like to be able to
know from the include directives of each file as much as I can about
the dependecies of that file.
b. I never noticed a significant speed advantage using PCH - although I
never actually timed and compared.

What are you opinions on the matter?

Used properly, precompiled headers do perceivably improve compilation
times. I think this is tangible.
Are there any known disadvantages to using PCH?

What you mentioned: less clear dependencies. Although there are
other ways to express these in C++ code, for example with namespaces.
And regarding MS-provided headers, anyway, you can hardly really
include "only what you want" (you're stuck with getting the
big blobs with all the macros herein).


Ivan
 
D

deanbrown3d

Our project at work takes about 1/5 of the time to build if you use
PCH. We put includes of all the reasonable static headers, such as
those for windows or VCL or dialogs all into one file, and use that as
the PCH. Most localized headers are left is includes AFTER the pragma
that tells it the PCH are done.

e.g.

#include "CommonHeaderDB4.h" // system headers and non-changing
headers, e.g. vcl.h
#pragma hdrstop

// Local headers
#include "uTrainExpandRoute.h"
#include "uLoadDistThread.h"
#include "fTrainMgr.h"
#include "uTrainSupport.h" //business logic of train for functions
too small to get their own file
#include "uCommonMain.h" //common variables including those
related to projects
#include "uEstimateVolume.h"


Dean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top