Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2001-03-19 07:34:40

At 09:50 PM 3/18/2001, Joe Gottman wrote:

>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) ==
>> != 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
>> a comment to the code mentioning that. Similar in shared_array. I
>> we could assert ((pn==rpn) == (px==rpx)), but it doesn't seem worth it
>> me.
>px != rpx isn't quite equivalent to pn != rpn. Consider the following
>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
>would have a memory leak in the pn's.

You're right! Thanks! I've changed the comment to read:

if (pn != rpn) { // Q: why not px != rpx? A: fails when both == 0

Greg in private email also pointed out a tricky case of when the pointers
aren't the same type but are related by multiple inheritance to point to
different places in the object. I'm going to have to think about that one.


Boost list run by bdawes at, gregod at, cpdaniel at, john at