4 ms·
This comment is exactly right, and is what I do whenever possible. However there are cases where a function may or may not need to copy a shared_pointer that wa
by usefulcat 7y ago
This comment is exactly right, and is what I do whenever possible. However there are cases where a function may or may not need to copy a shared_pointer that was passed to it as an argument. In such cases, the extra refcount updates that would be incurred for passing by value are not useful but still incur a cost. So my usual practice is to copy a shared_ptr only at the point where ownership needs to be shared.