智能智能(auto_ptr,unique_ptr,shared_ptr)(更新中。。。)
2016-03-11 11:59
405 查看
智能指针是为解决系统可能出现的内存泄漏问题而出现的。
void remodel(std::string &str)
{
std::string *ps=new std::string(str);
...
if(weird_thing)
throw exception();
str=*ps;
delete ps;
return;
}
当出现异常时,delete将不被执行,因此导致内存泄漏。智能指针则解决了这一问题。详见下面图片讲解。
void remodel(std::string &str)
{
std::string *ps=new std::string(str);
...
if(weird_thing)
throw exception();
str=*ps;
delete ps;
return;
}
当出现异常时,delete将不被执行,因此导致内存泄漏。智能指针则解决了这一问题。详见下面图片讲解。
相关文章推荐
- UIBezierPath+画板,签名档
- UItableView处于UITableViewStylePlain模式下如何取消HeaderView粘连性
- iOS UIAlertController 使用介绍
- suricata Quick Start Guide 启动手册
- UIView的Touch事件UIControlEvents详解
- HDU 2604 Queuing(矩阵快速幂)
- UI--手势识别器
- 《iOS Human Interface Guidelines》——Container View Controller
- Scene is unreachable due to lack of entry points and does not have an identifier for runtime access
- 如何解决androidstudio build项目png的iCCP警告
- "build gradle project info" Android Studio 导入Gradle工程时引发该问题的解决办法
- String.valueOf() 方法的使用
- 放在UIImageView上 按钮不能点击
- Android Bluetooth蓝牙开发\蓝牙协议\蓝牙通信例子_Android支持蓝牙4.0版本_BLE开发
- Contacts.CONTENT_STREQUENT_URI和Contacts.CONTENT_FREQUENT_URI
- UIImageView 图片变得模糊朦胧问题
- .Net自带ChartControl报错:Auto interval does not have proper value
- IOS-CAShapeLayer与UIBezierPath的基本用法
- RequireJS 依赖关系的实例
- hdu4893Wow! Such Sequence! (线段树)