ScopedPointer efficiency?


#1

Simple question, what’s more efficient in terms of CPU usage? ScopedPointers or a simple delete? I don’t know if I should use ScopedPointers in some critical objects…


#2

I would imagine that the costs of allocation/deallocation in the runtime’s heap functions would be orders of magnitude higher than the cost of the ScopedPointer operations.

Definitely not something to worry about, at all.


#3

And since ScopedPointer is fully defined at compile time, the compiler will actually not use any additional stack at all for it (it’s a pointer sized object anyway) and instead inline all the method calls.
So it does lower your risks of memory leaks and doesn’t really add any overhead, so use it whenever possible.


#4

Thanks to both, I’m going to abuse from it :wink: