Re: [Boost-users] shared_ptr vs ordinary pointers
Jonathan, Yes, I should have left out the delete() for the shared_ptr version since that's one if its big features. I have used shared_ptr code similar to your example, but I can't use it in the case I'm thinking of. This particular pointer needs to be passed around so a single scope doesn't work. Thanks, Merrill
Merrill Cornish wrote:
Yes, I should have left out the delete() for the shared_ptr version since that's one if its big features. I have used shared_ptr code similar to your example, but I can't use it in the case I'm thinking of. This particular pointer needs to be passed around so a single scope doesn't work.
If the shared_ptr is passed around by value, as a regular (*) pointer would be, it will correctly keep track of the reference count and delete only when there are no more referrers. -- That's basically the whole point of shared_ptr. If you didn't want the reference count you could just use scoped_ptr or std::auto_ptr. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - Grafik/jabber.org
participants (2)
-
Merrill Cornish
-
Rene Rivera