当前位置:网站首页>智能指针备注
智能指针备注
2022-06-24 06:44:00 【雾散睛明】
智能指针备注
c++标准库
memory
shared_ptr
weak_ptr
unique_ptr
shared_ptr:共享指针对象。采用引用计数得方式,决定指向得内存是否释放掉。
其中包括_uses计数和_weaks计数。
当新建一个 shared_ptr对象时,_uses和_weaks都为1.
将shared_ptr对象 赋值给 weak_ptr 时,_uses计数不变,_weaks 加1.
当将weak_ptr对象赋值给shared_ptr 时,_uses计数加1,_weaks计数不变。
shared_ptr 对象析构时,_uses 计数自减1,当_uses计数为0时,释放所指向得内存,并且_weaks 计数自减1.当_weaks 计数为0时,释放计数对象。
weak_ptr 析构时,_weaks 自减1,当_weaks 计数为0时,释放计数对象。
可以看出,weak_ptr对象并不释放指向得内存空间,只有shared_ptr负责释放指向得内存。
weak_ptr:常用于 shared_ptr 对象得交叉引用。
unique_ptr:享有内存的所有权,即同一时间只有一个unique_ptr指向拥有的内存。
boost库
scoped_ptr:用于在离开作用域时,释放对象,且不支持拷贝构造和赋值操作。
shared_ptr:和c++ shared_ptr 差不多。
weak_ptr:和c++ weak_ptr 差不多。
边栏推荐
- [vulhub shooting range]] ZABBIX SQL injection (cve-2016-10134) vulnerability recurrence
- 《canvas》之第1章 canvas概述
- PIP install XXX on the terminal but no module named XXX on pycharm
- New ways to play web security [6] preventing repeated use of graphic verification codes
- Super fast reading in OI
- PNAs: Geometric renormalization reveals the self similarity of multi-scale human connectome
- 2.1.1 QML grammar foundation I
- 【Django中运行scrapy框架,并将数据存入数据库】
- 10 common malware detection and analysis platforms
- MySQL - three tables (student, course, score) to query the name, number and score of students whose course is mathematics
猜你喜欢

2022年PMP项目管理考试敏捷知识点(1)

jarvisoj_ level2

How to delete / select an input method on your computer

jarvisoj_level2
![Selector (>, ~, +, [])](/img/7e/2becfcf7a7b2e743772deee5916caf.png)
Selector (>, ~, +, [])
![[wustctf2020] climb](/img/b6/4a0582144c3125e7a0666bbbbfe29d.png)
[wustctf2020] climb

How to open the soft keyboard in the computer, and how to open the soft keyboard in win10

图形技术之坐标转换
![[image fusion] image fusion based on NSST and PCNN with matlab code](/img/b4/61a5adde0d0bfc5a339ef8ab948d43.png)
[image fusion] image fusion based on NSST and PCNN with matlab code

图形技术之管线概念
随机推荐
Tencent cloud security and privacy computing has passed the evaluation of the ICT Institute and obtained national recognition
只显示两行,超出部分省略号显示
Global and Chinese market of water massage column 2022-2028: Research Report on technology, participants, trends, market size and share
Alibaba cloud full link data governance
get_started_3dsctf_2016
How VPN works
Spark stage and shuffle for daily data processing
Hubei College Upgraded to undergraduate - Hushi family planning department
Knowledge points of 2022 system integration project management engineer examination: ITSS information technology service
Analog display of the module taking software verifies the correctness of the module taking data, and reversely converts the bin file of the lattice array to display
《canvas》之第1章 canvas概述
Detailed explanation of C language compilation, link and operation
UTC、GMT、CST
Deploy L2TP in VPN (Part 1)
atguigu----16-自定义指令
[GUET-CTF2019]zips
Win10 build webservice
[WordPress website] 6 Article content copy prevention
[image fusion] image fusion based on NSST and PCNN with matlab code
10 common malware detection and analysis platforms