c++进阶
Douzi1024
这个作者很懒,什么都没留下…
展开
-
深入学习c++--智能指针(二) weak_ptr (打破shared_ptr循环引用)
目录1. 几种智能指针1.1 weak_ptr1.2 weak_ptr基本用法1.3 解决类之间循环引用1.4用 enable_shared_from_this从this转换到shared_ptr1. 几种智能指针1. auto_ptr: c++11中推荐不使用他(放弃)2.shared_ptr:每添加一次引用 就+1,减少一次引用,就-1;做到指针进行共享...原创 2019-05-02 21:01:52 · 2871 阅读 · 0 评论 -
深入学习c++--智能指针(三) unique_ptr
目录1. 几种智能指针1.1 unique_ptr1.2 注意1.3 使用方式1. 几种智能指针1. auto_ptr: c++11中推荐不使用他(放弃)2.shared_ptr:拥有共享对象所有权语义的智能指针3.unique_ptr:拥有独有对象所有权语义的智能指针4.weaked_ptr:到std::shared_ptr所管理对象的弱引...原创 2019-05-02 23:13:54 · 386 阅读 · 0 评论 -
深入学习c++--智能指针(四)--使用建议
1. 不要自己手动管理资源2. 一个裸指针不要用两个shared_ptr管理,unique_ptr3. 使用shared_ptr作为函数的接口,如果有可能用 const shared_ptr&的形式4. shared_ptr weak_ptr和裸指针相比,会大很多,并且效率上会有影响,尤其在多线程模式下。时间也上也是可以这么写:// 只进行一次new, 至少可以节...原创 2019-05-02 23:58:29 · 155 阅读 · 0 评论 -
深入学习c++--lambda函数
1. 简单使用#include <iostream>#include <functional>using namespace std;struct Print { void operator()(int a, int b, int c) const { cout << "a " << a <<...原创 2019-05-03 15:42:12 · 203 阅读 · 0 评论 -
深入学习c++--多线程编程(一)
1. 简介2. 线程使用2.1 demo#include <iostream>#include <thread>#include <future>using namespace std; void helloworld(){ cout << "hello world \n"; }int main(){...原创 2019-05-04 23:55:04 · 236 阅读 · 0 评论 -
深入学习c++--智能指针(一) shared_ptr
目录1. 几种智能指针1.1 shared_ptr1. 几种智能指针1. auto_ptr: c++11中推荐不使用他2.shared_ptr:每添加一次引用 就+1,减少一次引用,就-1;做到指针进行共享3.unique_ptr:一个指针同时只能有一个使用者使用4.weaked_ptr:与shared_ptr搭配使用1.1 shared_ptr参...原创 2019-04-30 00:17:45 · 438 阅读 · 0 评论 -
深入学习c++--多线程编程(二)【当线程间需要共享非const资源】
1. 遇到的问题#include <iostream>#include <thread>#include <chrono>#include <future>#include <cmath> #include <vector>#include <cstdlib>using namespace st...原创 2019-05-06 18:52:01 · 197 阅读 · 0 评论 -
深入学习c++--多线程编程(三)thread的两种死法
1. 生成了一个线程,需要告诉编译器是否管理必须告诉编译器是不管理还是管理,否则直接down了#include <iostream>#include <thread>#include <chrono>#include <future>#include <atomic>#include <cmath> #i...原创 2019-05-09 23:28:20 · 206 阅读 · 0 评论