【Cherno的C++视频】Precompiled headers in C++

预编译头文件(PCH)能显著提升C++项目的编译速度,通过一次性编译常用头文件并存储为二进制格式,避免重复读取。本文介绍了如何设置和使用PCH,强调不应包含频繁变动的文件,并指出其在处理第三方库如STL和Windows API时的优势。同时,注意PCH可能隐藏实际引用的细节,对编译时间敏感的项目尤其适用。
摘要由CSDN通过智能技术生成
 #include "pch.h"

// for a big project is quite useful.
// give you an opportunity to grad a bunch of header files and convert them into essentially
// a kind of compiled format that the compiler can use instead of having to read those header
// files over and over again. What it does is it takes a whole bunch of header files(a bunch
// of code essentially, for example:<vector>) which you tell it to take in and it compiles it 
// once and it stores it in a binary format that is way faster for the compiler to actually 
// deal with than just text. Everytime you include that precompiled header file(<vector>) 
// it already has everything you need, instead of passing that entire vector file every single
// time, it only needs to look at the precompiled header which is already in a great fast easy
// to use -> binary format.
// need to use it if you care about the compilation times.
// do not put frequently changing files into it.
// it's vitally used for code that isn't yours, for example STL, Windows API.
// on the other hand: it can potentially hide what's actually being used.

pch.h

#pragma once

#include <iostream>
#include <algorithm>
#include <functional>
#include <memory>
#include <thread>
#include <utility>

// Data structures
#include <string>
#include <stack>
#include <deque>
#include <array>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

// Windows API
#include <Windows.h>

pch.cpp

#include "pch.h"

右键pch.cpp -> 属性 -> C/C++ -> 预编译头
PrecompiledHeadersInCpp
右键需要使用的项目或者单个cpp文件 -> 属性 -> C/C++ -> 预编译头
PrecompiledHeadersInCpp
PrecompiledHeadersInCpp
查看【生成计间】对比使用预编译头文件与不使用。
PrecompiledHeadersInCpp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值