当前位置:网站首页>Dynamic memory and smart pointer
Dynamic memory and smart pointer
2022-07-29 01:54:00 【Matches - People】
One 、 Three memory areas
Two 、 Dynamic memory and smart pointer
1、 Operator new、delete
2、shared_ptr class

#include<memory>
#include<string>
using namespace std;
int main()
{
shared_ptr<string> p;
// If p Not empty , Check if it points to an empty string
if (p && p->empty())
{
}
return 0;
}

#include<memory>
#include<string>
#include"test.h"
#include"testClass.h"
using namespace std;
void f(testClass* p)
{
cout << "f" << endl;
delete p;
}
int main()
{
testClass* p;
if (true)
{
shared_ptr<testClass> sp(new testClass("123"),f);
p = sp.get();
}
p->name = "456";// And release , Cannot execute correctly
return 0;
}

shared_ptr<string> p1 = make_shared<string>();
auto p2 = make_shared<string>("CDA");3、unique_ptr class






4、weak_ptr

weak_ptr<string> wp(make_shared<string>("123"));
if (auto sp = wp.lock())// Determine whether it is null
{
}5、 Use standard
边栏推荐
- Slow storage scheme
- 【流放之路-第七章】
- Golang startup error [resolved]
- Data security is a competitive advantage. How can companies give priority to information security and compliance
- 【Golang】- runtime.Goexit()
- Tda75610-i2c-determination of I2C address of analog power amplifier
- Data platform data access practice
- Reinforcement learning (I): Q-learning, with source code interpretation
- Explanation of yocto project directory structure
- Plato launched the LAAS protocol elephant swap, which allows users to earn premium income
猜你喜欢

Alphafold revealed the universe of protein structure - from nearly 1million structures to more than 200million structures

Overview of Qualcomm 5g intelligent platform

The information security and Standardization Commission issued the draft for comments on the management guide for app personal information processing activities

OpenGL development with QT (II) drawing cube

易观分析:以用户为中心,提升手机银行用户体验,助力用户价值增长
![[web technology] 1395 esbuild bundler HMR](/img/74/be75c8f745f18b374ed15c8e1b4466.png)
[web technology] 1395 esbuild bundler HMR

Planning mathematics final simulation exam I

Introduction to Elmo, Bert and GPT

Network security litigation risk: four issues that chief information security officers are most concerned about

Reinforcement learning (II): SARS, with code rewriting
随机推荐
[the road of Exile - Chapter 6]
Tda75610-i2c-determination of I2C address of analog power amplifier
[netding cup 2020 rosefinch group]nmap
[the road of Exile - Chapter III]
活动速递| Apache Doris 性能优化实战系列直播课程初公开,诚邀您来参加!
Leetcode 112: path sum
ASCII code table
Planning mathematics final simulation exam I
With the explosive growth of digital identity in 2022, global organizations are facing greater network security
Google Cloud Spanner的实践经验
Day01作业
The new generation of public chain attacks the "Impossible Triangle"
【Golang】- runtime.Goexit()
【Web技术】1395- Esbuild Bundler HMR
[understanding of opportunity-54]: plain book-1-the origin of things [original chapter 1]: the road is simple.
Analysis of Multi Chain use cases on moonbeam -- review of Derek's speech in Polkadot decoded 2022
We summarized the three recommendations for the use of Nacos and first published the Nacos 3.0 plan for the 4th anniversary of the open source of Nacos
Plato launched the LAAS protocol elephant swap, which allows users to earn premium income
ELS square movement
T-sne dimensionality reduction