您的位置:首页 > 产品设计 > UI/UE

智能智能(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将不被执行,因此导致内存泄漏。智能指针则解决了这一问题。详见下面图片讲解。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: