当前位置:网站首页>The advantages of saving pointers when saving objects with vector and the use of reserve
The advantages of saving pointers when saving objects with vector and the use of reserve
2022-06-12 12:08:00 【Just want to call Yoko】
Code 1
Execution results 1
Code 2
result 2
Code 2 Commented out vec.reserve(3) open , result 3
The instructions are in use vector when , What is inserted is a copy of the object to be inserted , If vector When the class object in is large , Will affect performance , There are also some deep and shallow copy problems when using copy construction , In addition, through the results 2 And results 3 We can know when vector When there is not enough space to apply for , It will apply for space again and may give up the original space , In this way, the number of copy constructions called is more , So we're using vector It should be passed through its member function reserve Apply in advance for a value we estimate , You can rest assured , When reserve When the space is not enough , vector Will still automatically apply for space
Here's how to use vector The method of storing class pointers in , Be sure to insert vector The life cycle of the object pointer pointing to the content in , In addition, if it is new Coming out , If not elsewhere delete It should be traversed in due course vector Find out delete
result
边栏推荐
- 邻居子系统之ARP协议数据处理过程
- Kotlin扩展函数实现原理
- Pytoch notes
- 关于报文
- Must do skill -- use ffmpeg command to quickly and accurately cut video
- First understand the onion model, analyze the implementation process of middleware, and analyze the source code of KOA Middleware
- 6.6 rl:mdp and reward function
- 5g NR protocol learning -- ts38.211 downlink channel
- 5G NR協議學習--TS38.211下行通道
- ARM processor mode and register
猜你喜欢

Promise understanding has used promise to realize picture preloading (sequential loading)

PIP install in the CONDA environment cannot be installed into the specified CONDA environment (the default PIP installation location of the CONDA environment)

必杀技--使用FFmpeg命令快速精准剪切视频

The second day of QML study

QML学习 第二天

开源项目-(ERP+酒店+电商)后台管理系统

Create servlet project

无重复字符的最长字符串(LeetCode 3)

TinyMCE realizes automatic uploading of pasted pictures

【深度学习基础】反向传播法(1)
随机推荐
PIP install in the CONDA environment cannot be installed into the specified CONDA environment (the default PIP installation location of the CONDA environment)
SSL引入原因及加密步骤
淘宝新改版商家如何操作,需要注意的点有哪些
B. Wall painting (C language)
For in and object The difference between keys()
【Leetcode】199. Right view of binary tree
UML series articles (31) architecture modeling - deployment diagram
Visio 2019 uses PJ
服务端渲染与客户端渲染的区别(优缺点)
PDSCH related
The first thing with a server
【Leetcode】416. Split equal sum subset
【深度学习基础】神经网络的学习(4)
mysql复习
【Leetcode】79. Word search
Asynchronous path processing
bind、call、apply三者的区别,还有bind()的封装
Analyze the implementation principle of the onion model, and connect the onion model in your own project
【Leetcode】221. Largest Square
Cookies and sessions