Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of const boost::shared_ptr<T>& as function argument?

Tags:

c++

boost

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?

like image 689
Jan Ladislav Dussek Avatar asked Dec 20 '22 22:12

Jan Ladislav Dussek


1 Answers

Passing this by value is going to copy it which results in a reference count increment, synchronized across all threads. Definitely non-negligible.

like image 179
Steve Townsend Avatar answered Dec 24 '22 02:12

Steve Townsend