Boost logo

Boost :

Subject: Re: [boost] [valid_ptr] proposing a new type of pointer object that allows validity tracking without memory management and object ownership
From: Peter Dimov (pdimov_at_[hidden])
Date: 2011-03-16 10:40:15

Dan Walters wrote:
> I am posting to propose a new light weight pointer object library
> (boost.valid_ptr) that provides safe validity checking without having
> to take ownership or the the responsibility of memory management of
> the object pointed to.


> Detailed proposal:

This only works in single-threaded code, and even then, it can fail. In MT
code, it's possible that the object is destroyed after you called get() and
before you had the opportunity to look at the result (which is now a
dangling pointer). In ST code, things get interesting when in:

valid_ptr<X> px;

f() indirectly causes the object to be destroyed. This happens more often
than one might think. :-)

weak_ptr requires one to create a shared_ptr not because I wanted things to
be less efficient, but because this shared_ptr keeps the object alive; this
way, when you receive a positive answer from weak_ptr::lock, you can be sure
it stays positive.

Unless you're using null deleters of course, but the risk is all yours then.

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