In C++11 should we always use unique_ptr
or shared_ptr
instead of new
/delete
? How is it with performance, are smart pointers much slower?
unique_ptr
doesn't (isn't supposed to) have any runtime overhead whatsoever compared to using raw pointers. shared_ptr
does have some memory and time overhead (how much depends on the implementation). The practical overhead here can easily be zero if you actually need something that behaves like a shared_ptr
(that is, no other implementation you'd think of would be any faster or more memory efficient).
That is not to say you'll never use new/delete in your code, but it's not something you'll do all the time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With