Jump to content
  • Advertisement
Sign in to follow this  
Swarmer

Precompiled headers

This topic is 3629 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

Quick question: How exactly do precompiled headers work? What should I be putting in stdafx.h and .cpp, and where should I be including it? I read a bit about them but I'm still not sure; is it just a general file where all my #includes should go? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
For large projects, the compiler can spend a lot of time on header files.

It must open up every file that has been #include-ed and process it. It goes into the files that those files included, until it has processed all of them. When it starts the next .cpp file, it starts over, reprocessing all the same header files.

When a project gets really large, it can take a half hour or more for the compiler to go through all the headers for every file. It is extremely wasteful for the compiler to re-process every .h file for every .cpp file.

Precompiled headers work by the consolidating all the stuff you frequently compile, and dumping the preprocessed stuff into a huge intermediate file. Since this bundle is only processed once, you can cut your compile times by half or more.

Automatically generated precompiled headers make this easy, allowing the programmers to spend their time on important things rather than focusing on making the compiler run faster. There is no need to create a custom header file for it, assuming you set your options properly.


For large projects it can make sense for the build manager (that's their full-time job) to manually put together those files and not let the compiler do it. In that case, you generally include everything that is frequently used and everything with complex dependencies in their declarations.

For small projects I wouldn't bother with it. If your compile time is under a minute than it probably isn't worth it yet. In this case you should just include the files directly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Swarmer
Okay thanks!


Hm...
What does STDAFX stand for? Standard something. Dunno.


Wiki knows. "The AFX in stdafx.h stands for Application Framework eXtensions. AFX was the original abbreviation for the Microsoft Foundation Classes (MFC). Optionally, Visual Studio projects may avoid pre-compiled headers, as well as they may specify an alternative name (though stdafx.h is used by default)."

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!