tommy

It's hard to tell the world we live in is either a reality or a dream
posts - 52, comments - 17, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Boost.SmartPtr

Posted on 2011-03-23 10:01 Tommy Liang 阅读(237) 评论(0)  编辑 收藏 引用 所属分类: C++语言与规范

Use scoped_ptr when

  • A pointer is used in a scope where an exception may be thrown

  • There are several control paths in a function

  • The lifetime of a dynamically allocated object can be limited to a specific scope

  • Exception safety is important (always!)

Use shared_ptr in the following scenarios:

      When there are multiple clients of an object, but no explicit owner

  • When storing pointers in Standard Library containers

  • When passing objects to and from libraries without (other) expressed ownership

  • When managing resources that need special cleanup[9]

Use weak_ptr to

  • Break cyclic dependencies

  • Use a shared resource without sharing ownership

  • Avoid dangling pointers


check:http://my.oschina.net/jackwgm/blog/6695?catalog=23886


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理