|
Boost : |
From: Bjorn.Karlsson_at_[hidden]
Date: 2002-05-15 05:40:00
> From: Thomas Witt [mailto:witt_at_[hidden]]
>
> Peter,
>
> can you explain why make_shared adds safety. Currently I am
> unable to see why.
> IIUC what happens is a NULL ptr is dereferenced with or
> without make_shared.
> On the first look it seems as if make_shared pretends to be
> safe but isn't.
> When make shared is used the object might be gone already.
>
> Thanks
>
> Thomas
make_shared returns a shared_ptr that may contain a null pointer (thus, the
resulting shared_ptr should be tested before use). However, if the returned
shared_ptr contains a valid resource, then that shared_ptr can be safely
used because the reference count has been increased. That's not true for
weak_ptr, and that's why make_shared (and the constructor for shared_ptr
taking a weak_ptr as an argument) adds safety.
Bjorn Karlsson
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk