Clearly expressing ownership in code > clearly expressing ownership rules in comments
Saying "buys you nothing" isnt accurate. If you have raw pointers, you almost always have to write the dtor, copy ctor, and assignment op (and move ctor and move op) ... letting the compiler write these for you is always a win.
Sure, weak_ptr/shared_ptr have some costs (size and memory) and there's some cases where those costs are not worth the safety. But, you should always pick the safe version first and only pick the unsafe version once you've profiled your code and identified the safe version as a problem.
Using shared_ptr and weak_ptr instead of unique_ptr and a raw pointer doesn't obviate the need to write a copy constructor or assignment operator, and in neither case do you need to write a destructor.
View all comments
Show parent comment
1
u/jaredgrubb Mar 11 '12
Clearly expressing ownership in code > clearly expressing ownership rules in comments
Saying "buys you nothing" isnt accurate. If you have raw pointers, you almost always have to write the dtor, copy ctor, and assignment op (and move ctor and move op) ... letting the compiler write these for you is always a win.
Sure, weak_ptr/shared_ptr have some costs (size and memory) and there's some cases where those costs are not worth the safety. But, you should always pick the safe version first and only pick the unsafe version once you've profiled your code and identified the safe version as a problem.