4 ms·
No, I'm not advocating not using shared_ptr's for performance reasons. What I'm trying to say is that reference counting is not a universal solution and it shou
by exDM69 15y ago
No, I'm not advocating not using shared_ptr's for performance reasons. What I'm trying to say is that reference counting is not a universal solution and it should not be presented as one. It will also add a little bit of complexity to C++ programs and it has some "impedance mismatch" with pass-by-value semantics.
- cageface 15y agoIt's as close to a universal solution as you're going to get without a much more intrusive runtime. Obj-C and Python seem to get along just fine with it. I'd say that shared_ptr removes a lot more complexity than it adds in most code. What kind of impedance mismatch do you see with pass-by-value? You should be passing shared_ptr by value. One of the things I like about C++ is that it gives me choices and I still use raw pointers sometimes but shared_ptr removes a lot of manual memory management noise and makes it much easier to write robust, correct, exception-safe code.