Alex Rivera | Logout

Should we pass a shared_ptr by reference or by value?

Asked 2010-07-22T15:48:24.393
400

When a function takes a shared_ptr (from boost or C++11 STL), are you passing it:

  • by const reference: void foo(const shared_ptr<T>& p)

  • or by value: void foo(shared_ptr<T> p) ?

I would prefer the first method because I suspect it would be faster. But is this really worth it or are there any additional issues?

Could you please give the reasons for your choice or if the case, why you think it does not matter.

Edit
Report

1 Answer

-6

shared_ptr isn't large enough, nor do its constructor\destructor do enough work for there to be enough overhead from the copy to care about pass by reference vs pass by copy performance.

answered 2010-07-22T17:09:08.757

Your Answer