Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr vs pass object by reference
From: Max S. Kaznady (max.kaznady_at_[hidden])
Date: 2010-07-29 09:43:56

Cool, thanks! I thought I was missing something. I think I have to use
shared_ptr then, because my code is shared among various parallel
OpenMP workers... I'll post here again if my parallelization doesn't
work out. The arrays are sliced, but I have other data structures
which keep track of these slices, and those are better off with
shared_ptr IMO.


On Thu, Jul 29, 2010 at 5:10 AM, Patrick Loney
<patrick.loney_at_[hidden]> wrote:
>> Can I still pass that pointer by value into a function like I did with shared_ptr in the
>> above example?
> No, you can't take a copy of a scoped ptr, when one goes out of scope it automatically causes the pointed to object to destruct, if there are two scoped ptrs pointing to the same object what would happen when the second is then used to access the already destructed object? You can pass scoped ptrs by reference, use shared pointers when you want multiple objects to have ownership of the pointed to object (i.e. no object can destroy the contents of the shared pointer while another object still needs it).
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at