5 ms·
But what if I sometimes want to retain shared ownership? I don't want to receive the shared_ptr by value because that drastically slows down my program for the
by afc 7y ago
But what if I sometimes want to retain shared ownership? I don't want to receive the shared_ptr by value because that drastically slows down my program for the cases where I end up not retaining ownership (compared to const-ref), but I can't just take the const ref Widget.
- zeotroph 7y agoHence most likely. But when you are throwing around shared pointers left and right the program is usually already in the phase of "I don't know... just stick into a shared_ptr to be safe".
- butterisgood 7y agoAnd that’s my concern too. Shared pointers aren’t free. You can solve problems with them but the moment I see them in code it raises flags that make me think someone gave up solving the actual problem at hand and “this seemed to work”. I’ve seen many an otherwise good looking code base paint itself into corners over object ownership, life cycles and resource reclamation.