Roland said:
Yes, of course. Actually, inefficiency is Stroustrups major argument
against ref-counted s.p. (
http://www.research.att.com/~bs/DnE2005.pdf
look for "Smart pointer").
The key part is: 'Smart pointers are popular, but should be approached
with care. They are not the panacea that they are sometimes presented
to be. In particular, they are far more expensive to use than ordinary
pointers, destructors for objects "owned" by a set of shared_ptrs
will run at unpredictable times, and if a lot of objects are deleted at
once because the last shared_ptr to them is deleted you can incur
"garbage collection delays" exactly as if you were running a
general collector. The costs primarily relate to free store allocation
of use count objects and especially to locking during access to the use
counts in threaded systems. Do not simply replace all your ordinary
pointers with smart_ptrs if you are concerned with performance or
predictability. These concerns kept smart_ptrs "ancestor",
counted_ptr, out of the 1998 standard.'
It is not likely, however, that these concerns will keep them out of
C++0x, not least because our collective experienced with smart pointers
has increased since 1998. Not to disregard the venerable Creator's
words, but other gurus have made the opposite case that "Correctness is
worth the cost [of smart pointers]" (C++ Coding Standards, item 60),
and they suggest "If you use [Boost] and [TR1] for nothing else, use
them for shared_ptr."
IMO, 'transfer' semantics is the stronger argument against s.p.
Please elaborate. (We all know about std::auto_ptr. What about
std::tr1::shared_ptr or boost::scoped_ptr, which doesn't allow
transferring at all?)
S.p. create more problems WRT ownership that they solve.
Bald assertions don't prove your case.
RAII. I mean pure RAII so that "allocation and deallocation disappear
from the surface level of your code"
(
http://www.artima.com/intv/modern3.html). Encapsulation without
transfer of ownership.
The explicit purpose of std::auto_ptr is to support RAII (TC++PL,
14.4.2).
Cheers! --M