> Programming Languages > C++
Various Topics Home | Disclaimer | Report Adult Posts

Various Topics on C++



C++ - "boost::shared_ptr vs. auto_ptr" in Programming Languages


Old 06-19-2004   #1
..i..
 
Default boost::shared_ptr vs. auto_ptr

Are there any advantages of using boost::shared_ptr other than auto_ptr from
standard library?



 
Old 06-19-2004   #2
..f .. ..einba..
 
Default Re: boost::shared_ptr vs. auto_ptr

* ctick:
> Are there any advantages of using boost::shared_ptr other than auto_ptr from
> standard library?


There are a number of advantages.

First, they're two different beasts: std::auto_ptr transfers ownership
so that with some caution you can guarantee that only one pointer points
to a particular object at any time, whereas boost::shared_ptr provides
reference counting so that many pointers can point to the same object.

Second, you cannot put std::auto_ptr's in a standard container, but you
can with boost::shared_ptr.

Third, although the standard specially provides for calling a destructor
on an object of incomplete cl***, not all compilers support that. This
problem pops up in e.g. the pimpl idiom. With boost::shared_ptr you
replace the direct delete expression in std::auto_ptr with a custom
destroy-function that can be defined where the full definition of the
cl*** is available, side-stepping the issue.

I could list up a fourth and fifth advantage, and perhaps more, but I
think that's enough. The main advantage of std::auto_ptr is that it's
always there and that it's standard. It should therefore be used when
the generality of e.g. boost::shared_ptr is not required.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Old 06-19-2004   #3
..v.. ..rm..
 
Default Re: boost::shared_ptr vs. auto_ptr

On Sat, 19 Jun 2004 20:23:26 GMT in comp.lang.c++, alfps@start.no (Alf
P. Steinbach) wrote,
>I could list up a fourth and fifth advantage, and perhaps more, but I
>think that's enough. The main advantage of std::auto_ptr is that it's
>always there and that it's standard. It should therefore be used when
>the generality of e.g. boost::shared_ptr is not required.


I think that auto_ptr also has less overhead cost than shared_ptr's
ownership tracking mechanism when you are doing the simple things it is
capable of and have no need for shared ownership.

 
Old 06-20-2004   #4
..em.. ..r..
 
Default Re: boost::shared_ptr vs. auto_ptr

"ctick" <ctick@flare.com> wrote in message
news:g61Bc.6352$OB3.4344@bgtnsc05-

> Are there any advantages of using boost::shared_ptr other than auto_ptr

from
> standard library?


You're comparing apples to oranges.


 

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0