在预编译头中放什么? (MSVC) [英] What to put in precompiled header? (MSVC)

查看:159
本文介绍了在预编译头中放什么? (MSVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是预编译头文件的最佳候选人?我可以把STL和Boost标头放在那里,即使他们有模板吗?并且会减少编译时间吗?
此外,什么是最好的IDE设置来减少编译时间?

What are the best candidates for a precompiled header file? Can I put STL and Boost headers there, even though they have templates? And will that reduce compile times? Also, what are the best IDE settings to reduce compile times?

推荐答案

当生成预编译头文件时,编译器解析头文件(一个重要的任务!),并将其转换为为编译器的优点优化的二进制格式。

When generating a precompiled header file, a compiler parses the header text (a significant task!), and converts it into a binary format that is optimised for the compiler's benefit.

即使模板类将在其他.cpp文件编译时实例化,它们将从预编译头中的信息实例化,这对于编译器读取显着更快。

Even though the template classes will be instantiated when other .cpp files are compiled, they will be instantiated from information in the precompiled header, which is significantly faster for the compiler to read.




(later addition)

你应该包括在预编译头中的一件事是作为项目一部分并且频繁更改的文件即使每个.CPP文件都包含这些文件。

One thing that you should not include in a precompiled header are files that are part of your project and are changed frequently, even if every single .CPP file includes these files.

原因是这样的 - 生成预编译头可能需要很长时间,因为boost,stl和Windows库非常大。

The reason is this - the generation of the precompiled header can take a long time, because the boost, stl and windows libraries are very large.

你可能有一个简单的文件(例如StringDefs.h)。如果StringDefs.h包含在stdafx.h中,并且有一个开发人员使用StringDefs.h,那么每个开发人员都必须等待整个预编译头重新编译。如果StringDefs.h被省略了预编译的头,并且每个.CPP文件被解析,这会更快。

You might have a simple file (eg "StringDefs.h") that everything uses. If StringDefs.h is included in stdafx.h, and one developer touches StringDefs.h, then every developer has to wait until the entire precompiled header recompiles. It would be much faster if StringDefs.h was left out of the precompiled header, and parsed along with each .CPP file.

这篇关于在预编译头中放什么? (MSVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆