scoped_ref

实现RAII chromium 有两个类
一个是 RefCounted 类
需要实现引用计数的的类都要继承此类

// A base class for reference counted classes.  Otherwise, known as a cheap

// knock-off of WebKit's RefCounted<T> class.  To use this guy just extend your

// class from it like so:

//

//   class MyFoo : public base::RefCounted<MyFoo> {

//    ...

//    private:

//     friend class base::RefCounted<MyFoo>;

//     ~MyFoo();

//   };

使用通过一个scoped_refptr 指针类来管理

View Code
//

// A smart pointer class for reference counted objects.  Use this class instead

// of calling AddRef and Release manually on a reference counted object to

// avoid common memory leaks caused by forgetting to Release an object

// reference.  Sample usage:

//

//   class MyFoo : public RefCounted<MyFoo> {

//    ...

//   };

//

//   void some_function() {

//     scoped_refptr<MyFoo> foo = new MyFoo();

//     foo->Method(param);

//     
// |foo| is released when this function returns

//   }

//

//   void some_other_function() {

//     scoped_refptr<MyFoo> foo = new MyFoo();

//     ...

//     foo = NULL;  
// explicitly releases |foo|

//     ...

//     if (foo)

//       foo->Method(param);

//   }

//

 

其实用法和OSG的相同,内部实现也应该相同吧。没有去具体看代码。

 

转载于:https://www.cnblogs.com/geometry-/archive/2012/07/08/2581529.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值