Is there a way to increase the efficiency of shared_ptr by storing the reference count inside the controlled object?

前端 未结 4 2113
有刺的猬
有刺的猬 2021-01-20 19:15

This is becoming a common pattern in my code, for when I need to manage an object that needs to be noncopyable because either A. it is \"heavy\" or B. it is an operating sys

4条回答
  •  太阳男子
    2021-01-20 19:44

    you can save some overhead by simply getting rid of the two classes and having just one and typedefing a shared ptr to it - this is the idom i use all the time

     class Resource
     {
          ...
     };
     typedef boost::shared_ptr ResourcePtr;
    

提交回复
热议问题