Skip to content

Commit 850a0a4

Browse files
committed
2024年1月17日18:15:23
2 parents 1030d73 + 6248610 commit 850a0a4

File tree

6 files changed

+1704
-732
lines changed

6 files changed

+1704
-732
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Declare files that will always have LF line endings on checkout.
2+
*.md text eol=native
3+

cxx/gist.md

+144-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,144 @@
1-
## 编码
2-
3-
跨win/linux项目的编码选择和编译选项设置,首选: UTF-8 With BOOM
4-
5-
以下是对编码造成问题的说明
6-
7-
https://github.com/lovepika/thinking_file_encoding_cpp
8-
9-
## 多线程
10-
11-
## 线程池
12-
13-
```c++
14-
15-
```
1+
2+
## 编码
3+
4+
跨win/linux项目的编码选择和编译选项设置,首选: UTF-8 With BOOM
5+
6+
以下是对编码造成问题的说明
7+
8+
https://github.com/lovepika/thinking_file_encoding_cpp
9+
10+
## 多线程
11+
12+
## 线程池
13+
14+
```c++
15+
16+
```
17+
=======
18+
## 编码
19+
跨win/linux项目的编码选择和编译选项设置,首选: UTF-8 With BOOM,以下是对编码造成问题的说明
20+
21+
参考链接: https://github.com/lovepika/thinking_file_encoding_cpp
22+
23+
Visual Studio Code 配置 C/C++ 开发环境的最佳实践(VSCode + Clangd + XMake)
24+
25+
参考链接: https://zhuanlan.zhihu.com/p/398790625
26+
27+
28+
---
29+
## c++代码调试的艺术
30+
微信读书,讲解了VS2022的调试,以及linux下c++的调试技巧
31+
32+
参考链接: https://weread.qq.com/web/reader/423320c07228f7b6423975a
33+
34+
在VS studio中调试dll的方法(软件调用dll),可以附加到进程,也可以开启本地调试
35+
36+
参考链接:https://blog.csdn.net/daidi1989/article/details/79916399
37+
38+
在VS studio查看内存的办法
39+
```c++
40+
#可以查看此地址的内存变量,适用于指针数组
41+
float*),0xxxx00000,1000
42+
```
43+
44+
---
45+
## c++性能优化
46+
要优化程序执行效率,第一步就是发现执行过程中的热点问题。大多数情况下,需要依靠专门的工具采集信息,并且将性能问题可视化。比如:火焰图、调用链路耗时分布图,cpu cache命中次数,段页切换次数等。
47+
常见工具:gpref,valgrind,profiling(CLion内置,可一键生成火焰图),SLS(特别适用于分布式场景,强烈推荐),vld,Arthas(阿里出品,Java程序性能分析神器),apiMonitor,permon(windows自带性能分析工具)
48+
49+
参考链接:http://www.chunel.cn/archives/topic-01-performanceoptimization
50+
51+
---
52+
## C++ DLL导出类 知识大全
53+
普通的导入导出C++类的方式都是使用_declspec(dllexport) /_declspec(dllimport)来导入导出类,但是在公司的开发中我们没有导入导出,而是定义了一些只有纯虚函数的抽象类,然后定义了一个工厂类,将这个工厂类注册到框架的服务中心中,使用时从服务中心拿到这个工厂类,就可以创建Dll中的其它类。
54+
55+
参考链接 https://www.cnblogs.com/lidabo/p/7121745.html
56+
```c++
57+
//2011.10.6//cswuyg//dll导出类//dll跟其使用者共用的头文件
58+
#pragma once
59+
#ifdef MATUREAPPROACH_EXPORTS
60+
#define MATUREAPPROACH_API __declspec(dllexport)
61+
#else
62+
#define MATUREAPPROACH_API __declspec(dllimport)
63+
#endif
64+
class IExport
65+
{
66+
public:
67+
virtual void Hi() = 0;
68+
virtual void Test() = 0;
69+
virtual void Release() = 0;
70+
};
71+
extern "C" MATUREAPPROACH_API IExport* _stdcall CreateExportObj();
72+
extern "C" MATUREAPPROACH_API void _stdcall DestroyExportObj(IExport* pExport);
73+
```
74+
```c++
75+
//2011.10.6//cswuyg//dll导出类// 实现类
76+
#pragma once
77+
#include "MatureApproach.h"
78+
class ExportImpl : public IExport
79+
{
80+
public: virtual void Hi();
81+
virtual void Test();
82+
virtual void Release();
83+
~ExportImpl();
84+
private:
85+
};
86+
```
87+
88+
---
89+
## std::move
90+
在开发过程中,全程传参和赋值中,采用的都是std::move和emplace的传递方式,尽可能的避免出现中间流程无意义copy的情况。
91+
92+
---
93+
### std::unique_ptr
94+
shared_ptr和unique_ptr在反复多次申请和来回赋值的情况下,有一定的性能差距,同时shared_ptr自身内存占用也比unique_ptr大(主要都是因为shared_ptr中的cas校验机制)。很多大型项目,是明文禁止使用shared_ptr的。大家平日写代码的时候,可以注意一下不需要共享所有权时应该使用unique_ptr而不是shared_ptr.
95+
unique_ptr从概念上更简单,动作更加可预见(你知道析构动作什么时候发生)而且更快(不需要隐式维护使用计数)。
96+
如果函数使用shared_ptr管理其内局部分配的对象,但是从来没有返回该智能指针或者将其传递个一个需要shared_ptr&的函数,发出警告。建议使用unique_ptr。
97+
98+
```c++
99+
//反面示例
100+
void f()
101+
{
102+
shared_ptr<Base> base = make_shared<Derived>();
103+
// use base locally, without copying it -- refcount never exceeds 1
104+
} // destroy base
105+
106+
//下面的代码更高效
107+
void f()
108+
{
109+
unique_ptr<Base> base = make_unique<Derived>();
110+
// use base locally
111+
} // destroy base
112+
```
113+
114+
---
115+
## 模板编程
116+
github 的一个仓库这个可以主要看一下。参考链接: https://github.com/wuye9036/CppTemplateTutorial
117+
118+
小亮老师的课程也可以看一下,看一下模板编程的内容。
119+
120+
B站主页: https://space.bilibili.com/263032155/channel/collectiondetail?sid=53025
121+
122+
github链接: https://github.com/parallel101/course
123+
124+
![](../images/c++_1.png)
125+
126+
---
127+
## 设计模式
128+
129+
22种设计模式的C++实现
130+
131+
参考链接: https://zhuanlan.zhihu.com/p/476220724
132+
另外的比较简洁的代码实现。
133+
134+
参考链接:https://gitee.com/naoano/design_pattern
135+
常用的设计模式:工厂模式,桥接模式,观察者模式,状态模式。
136+
137+
---
138+
## 多线程
139+
140+
141+
---
142+
## 线程池
143+
144+

images/c++_1.png

281 KB
Loading

0 commit comments

Comments
 (0)