Boost logo

Boost :

From: Joe Gottman (joegottman_at_[hidden])
Date: 2001-03-18 21:50:55


----- Original Message -----
From: "Beman Dawes" <bdawes_at_[hidden]>
> >1. In share(), shouldn't the code "if (pn != rpn)" be "if (px !=
> >rpx)"?
>
> They are equivalent. Something is disastrously wrong if (pn != rpn) ==
(px
> != rpx). Think about it. If the two object pointers point to the same
> object, the two count pointer had better point to the same count. I'll
add
> a comment to the code mentioning that. Similar in shared_array. I guess
> we could assert ((pn==rpn) == (px==rpx)), but it doesn't seem worth it to
> me.

px != rpx isn't quite equivalent to pn != rpn. Consider the following code:

shared_ptr<int> p1, p2; // p1 and p2 are both initialized with px == 0
p1 = p2; // px 's are equal, pn's are not. If share were to compare px's we
would have a memory leak in the pn's.

Joe Gottman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk