Sign in to follow this  

Precompiled header or not precompiled header... that is the question...

This topic is 4485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, in loads of code around for gamedev type stuff i never see anyone using precompiled headers. Is there a reason for this? Generally i try to use them whereever i can to speed up the compile time. What do most of you do? Precompiled or not? Cheers

Share this post


Link to post
Share on other sites
Pch's can rock! It's really something that helps big projects with lots of header includes. If there's something that changes rarely enough that you don't mind a full recompile every time you change it... Toss it in the PCH!

A total guesstimate would be if you have a project with more than 20 cpp files that each include more than 5 rarely changed .h files before you start to notice a difference. YMMV.

(Deyja is right that they are sort of a hack to avoid worrying about dependencies... so at least realize that it is a hack. You're essentially pretending you don't have dependencies by sticking your fingers in your ears and going "La-la-la-la-la" while it says 'Building Pre-compiled Headers...' -- and then watching the rest of your project build super-fast.)

Share this post


Link to post
Share on other sites
Quote:
Original post by Skute
What do most of you do? Precompiled or not?


Pretty much if I make a project, I never use PCH files. Most of the time I don't have a project where it's needed, and in the few times that it might help out a little, I don't bother with it. Mainly because it's a pain when you add source files and get the PCH cannot be found for this .CPP file. It's correctable by including in the PCH or disabling PCH support on the source file, but that's too much extra work for the rewards.

Then again, I do have a relativly fast computer, so compile times on my own projects are not much of a problem ever. [wink]

Share this post


Link to post
Share on other sites
I don't use them since it won't let me use my codebase (cpp/h files included from a common folder) with MFC. Unless i'd add stdafx.h to them. Or include stdafx.h before the common includes. Too much headache involved.

And i actually never noticed a huge boost in compile speed with them.

Share this post


Link to post
Share on other sites
Most definately use them. I lose enough productivity as it is waiting for builds to finish. I've successfully gotten most of my coworkers to start using them as well once I showed them how lightning fast my full builds were compared to theirs. :)

The pros will far outweigh the cons. I don't mind being slightly inconvenienced by prefixing all my files with the #include for it.

Share this post


Link to post
Share on other sites
If you've never noticed much of boost, then chances are they aren't set up correctly. For example, Visual Studio's default is set to "automatically generate" which is rubbish. You have to set it to "use precompiled header" instead to get any performance gains. And if you include a header in your pch, don't include it elsewhere. Even if all you do is throw windows.h and a couple stl headers in there, you just saved a lot of parsing time.

They won't make sense for every project, just most of them. Honestly, it's really worth the time to figure out how to correctly and properly set up your project to support it. My build times went from over five minutes to under 45 seconds. Trust me, that adds up significantly over the course of a project.

I used this article on PCH's to figure out how to set them up correctly and it really helped a lot. I would definately check it out and see if it will work for you. It's worth a few minutes of research.

PCH Article

Share this post


Link to post
Share on other sites
yeah i do use PCH in normal every day working life, it cuts our compile times down from 8mins to approx 2mins. a huge difference.

but i was wondering if it was better to work out the depenendcies yourself so that you can easily swap modules in or out etc.

if you setup PCH correctly (ie using PCH not auto generate) you can notice a difference straight away.

Share this post


Link to post
Share on other sites

This topic is 4485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this