The Leak of The Memory in C++ 1.2
来源:互联网 发布:孙悟空知乎 编辑:程序博客网 时间:2024/06/05 07:05
The Leak of The Memory in C++ 1.2
Last time I showed a smart pointer has some side effect. This time
I'll show you another smart pointer which is much better. Now our hero will show
his ability.
The shared_ptr, this smart pointer looks like a raw pointer when
people use it. Which introduced by boost - one of most inportant c++ libraries. We can
use this smart pointer like the last smart pointer which I already introduced.
Just like this.
And you can assign value to them, just like this.
You can use this smart pointer in 99% situation without any
consideration.
This smart pointer is very, very important, it should been konwn by every C++ programmer as int type..
And this smart pointer already is part of C++11, means you can use it
any where any time. The demo code is below:
appMain.h
Last time I showed a smart pointer has some side effect. This time
I'll show you another smart pointer which is much better. Now our hero will show
his ability.
The shared_ptr, this smart pointer looks like a raw pointer when
people use it. Which introduced by boost - one of most inportant c++ libraries. We can
use this smart pointer like the last smart pointer which I already introduced.
Just like this.
shared_ptr<Person> p1(new Person); shared_ptr<Person> p2(new Person);
And you can assign value to them, just like this.
shared_ptr<Person> p1(new Person); shared_ptr<Person> p2 = p1; shared_ptr<Person> p3(new Person); p3 = p1;
You can use this smart pointer in 99% situation without any
consideration.
This smart pointer is very, very important, it should been konwn by every C++ programmer as int type..
And this smart pointer already is part of C++11, means you can use it
any where any time. The demo code is below:
appMain.h
#include <iostream>#include <boost/shared_ptr.hpp>#include "Person.h"using namespace std;using namespace boost;int main(int,char**){ shared_ptr<Person> p1(new Person); shared_ptr<Person> p2(new Person); shared_ptr<Person> p3 = p2; p3 = p1; return 0;}
0 0
- The Leak of The Memory in C++ 1.2
- The Leak of The Memory In C++ 1.1
- the leak of the memory in c++ 03
- The problem of Memory Leak
- In the name of memory
- The mechanism and implementation of detecting memory leak
- The tools that check memory leak of python program
- What is the best free memory leak detector for a C/C++ program and its plug-in DLLs
- What is the best free memory leak detector for a C/C++ program and its plug-in DLLs
- Find the memory usage, footprint, leak
- Memory management in C: The heap and the stack
- Allocationand Reuse of Memory in the Shared Pool
- ads 1.2 memory map of the image
- memory leak in occi
- Memory leak in WebView
- The understanding of string in C.
- The use of sizeof in C
- The summary of virtual memory
- 再解Java中的String
- 有一行字符,统计其中的单词个数(单词之间以空格分隔),并将每一个单词的第一个字母改为大写。
- Orcale监听错误
- servlet 多线程安全性问题分析
- http web 应用服务器
- The Leak of The Memory in C++ 1.2
- Exercise 43:基本的面向对象的分析和设计
- 如何加入一个开源项目?
- linux杂谈(十):初次接触selinux
- 出差回来对公司开发工作的感想
- 异步ping的实现,如何在10秒内ping完20000个设备
- 1.01一个单向链表,不知道头节点,一个指针指向其中的一个节点,问如何删除这个指针指向的节点?
- The difference between intent and events
- python sax方式解析xml