Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr vs pass object by reference
From: Michael Jackson (mike.jackson_at_[hidden])
Date: 2010-07-28 12:05:12


On 7/28/10 11:50 AM, in article
9FA45EF1AB90804BB8FF5A4A8AD0B97305A895A964_at_IE2RD2XVS031.red002.local,
"Patrick Loney" wrote:

>>>
>>>> If I can pass the object by reference to a function, then is there a
>>>> need to use shared pointers?
>>>
>>> Not if you know the lifetime of your object and it won't be deleted before
>>> the
>>> function has finished. You may find scoped pointers useful though:
>>> http://www.boost.org/doc/libs/1_43_0/libs/smart_ptr/scoped_ptr.htm
>
>> I use shared_ptr like a "poor-man's" garbage collection. Instead of having
>
> Ahh, being a c++ developer I see garbage collection as a poor man's raii (you
> can't even control when something is destructed for gods' sake ;))
>

Not sure if "Garbage Collection" was the best use here. A better term in my
mind should have been "Memory Management". Thanks for the sanity check on
RAII. I'll review my architecture again to make sure we are using the best
for our project.

>> Maybe I am using shared_ptr wrong but at least for my project it seems to
>> work well.
>
> Scoped_ptr offers the automatic memory management you discuss without the
> additional functionality of shared_ptr (i.e. shared_ptr is a scoped_ptr with
> added reference counting functionality)
Thanks. I'll take a look.

Mike Jackson


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net