shared_ptr
is more heavyweight than scoped_ptr
. It needs to allocate and free a reference count object as well as the managed object, and to handle thread-safe reference counting – on one platform I worked on, this was a significant overhead.
My advice (in general) is to use the simplest object that meets your needs. If you need reference-counted sharing, use shared_ptr
; if you just need automatic deletion once you’ve finished with a single reference, use scoped_ptr
.