Project

General

Profile

Actions

Task #1912

closed

Stop using const shared_ptr<T>& parameter type

Added by Junxiao Shi over 9 years ago. Updated over 9 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Category:
Utils
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Some code is declaring const shared_ptr<T>& as parameter type.

This is potentially bad, because:

  • It's risky to pass shared_ptr by const reference, because there is no guarantee that the pointer would remain valid throughout the function call: the function may have a side effect of destroying the pointer. ref
  • Passing by const reference instead of passing by value is a performance optimization, but this optimization is premature because it's not justified by benchmark.

We should stop adding new functions that declares const shared_ptr<T>& parameter type, and gradually change existing functions to pass shared_ptr by value.


Files

sharedptr-bench.cpp (779 Bytes) sharedptr-bench.cpp Junxiao Shi, 08/22/2014 09:38 PM
Actions

Also available in: Atom PDF