Reputation: 1475
I'm trying to choose proper files as precompiled headers to decrease time of compilation. I use VS2013. I know that should be files out of my code (for examples libraries etc. to not recompile everything) or files from my code that I won't change a lot or files from my code that are included everywhere or almost everywhere.
What if I have for example 150 files to compile and 25 of them includes some header file X.hpp (from outsource library). Should I add it to precompiled header? Does it make sense? How about rest of files (files that not include X.hpp)? Won't they much have longer compile time?
Do you know how size of precompiled header influence to time of compilation? I have 10GB of ram memory. Is it a good idea to add to stdafx.h file as much as visual studio let me?
Upvotes: 1
Views: 224
Reputation: 1621
If you have a file which is included in many of your translations units, then yes it should go in the PCH.
Build time optimization is a process of trial and error. PCH can help amortize the costs of compiling some things, but it's not a complete solution. If you're making heavy use of templates (generative coding), then the template instantiations can cause a lot of build overhead which may not be helped by the PCH.
You should also consider forward declarations and the pimpl idiom. In my experience, with big projects, reducing header dependencies often leads to the biggest reduction in build times.
Upvotes: 2