#precompile header

3 messages · Page 1 of 1 (latest)

autumn walrus
#

I am really confuse, what is the cons of using pch, for a specific project I am working on?(not sharing pch with multiple project)

The worse case of pch is recompiling (I assume), I expect recompiling would do exactly what it does when doing normal compilation without pch of the same header.

Reading some reddit and chatgpt, they said that it might be slower when pch initially compile compare to a normal compilation. Is that true? If so, why?

tough bayBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

fiery temple
# autumn walrus I am really confuse, what is the cons of using pch, for a specific project I am ...

If you have 100 .cpp files all doing #include <vector> and #include "my_massive_header.h", every single one of those .cpp files will have to parse those two headers.

So instead, you can compile those two headers into a .pch just once, and include that .pch in those 100 .cpp files, so that the .cpp files don't have to do any parsing of those headers anymore. So this will likely speed up the compilation of the 100 .cpp drastically.

But if you change something in my_massive_header.h even the slightest bit, then you'd of course have to regenerate the .pch, and then all those 100 .cpp files would have to be recompiled again. So only put stuff you don't intend to change often in the .pch.