Re: Unusual usage of IUknown
Stephan T. Lavavej [MSFT] wrote:
VC9 SP1 contains optimizations to avoid incrementing and decrementing
shared_ptr's refcount (e.g. when reallocating a
vector<shared_ptr<T>>). VC10's move semantics extend this even
further. Also, VC10's make_shared<T>() eliminates the overhead of
having two dynamic memory allocations; it's able to put the object
and its reference count control block in the same chunk of memory,
which gives you efficiency very close to that of intrusive reference
counting.
I'm sure the move semantics in VC10 would have made my Spirit test go MUCH
faster. A very large portion of the overhead that I measured was from
copying of shared_ptr's.
Of course, shared_ptr uses interlocked operations for threadsafe
refcounting. Naive intrusive refcounts that use ordinary increments
and decrements will obviously be faster, but restricts ownership to a
single thread.
Naturally!
At the time, I wanted a shared_ptr that gave me the choice of whether I
wanted thread safety or not. I'm still on the fence as to whether this
would be a good option - I'm sure it would be abused by many naive users
looking for unneeded optimizations and instead creating concurrency problems
that would be had to track down.
STL
-cd