I'm using a certain large and well-maintained open-source C++ library and came across a class definition having a constructor of the form
class SomeClass {
SomeClass( const boost::shared_ptr<SomeOtherClass>& );
}
My question is: what's the point of passing a const boost::shared_ptr<T>
by reference? Is there really a non-negligible amount of overhead associated with passing a boost::shared_ptr<T>
by value, or is there some other kind of danger to passing a boost::shared_ptr<T>
by value that I'm not aware of?
Passing this by value is going to copy it which results in a reference count increment, synchronized across all threads. Definitely non-negligible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With