|
Boost : |
From: Alan Griffiths (alan_at_[hidden])
Date: 1999-08-01 16:12:05
In message <000801bedc3e$fb008170$37781990_at_[hidden]>, Greg Colvin
<gcolvin_at_[hidden]> writes
>Although it seems impossible to create a non-intrusive weak
>pointer class that can track the liveness of an arbitrary class of
>object, it is possible to create one that tracks the liveness of
>objects controlled by shared_ptr.
>
>The changes to out current shared_ptr would be:
>
> Switch to the "indirect" implementation of shared_ptr. That
> is, the shared_ptr contains just a pointer to a handle struct
> containing a pointer to the object shared and the count.
>
> Add a second count field for the number of weak pointers using
> the object. When the number of shared pointers goes to zero
> the shared object is deleted and the pointer to object field is
> zeroed out, but the handle struct is not deleted until both
> counters go to zero.
There is an existing, tested implementation along these lines on my
website (I called the pointers "counted_ptr" and "uncounted_ptr"). If
anyone wants to bring these into boost format and submit them then I
hearby grant permission. (I was hoping to do this myself, but I won't
have time for the foreseeable future.)
There is also a smart pointer that replicates the referenced object on
assignment.
There is an overview at:
http://www.octopull.demon.co.uk/arglib/
-- Alan Griffiths (alan_at_[hidden]) http://www.octopull.demon.co.uk/ ACCU Chairman (chair_at_[hidden]) http://www.accu.org/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk