|
Boost : |
From: Larry Evans (jcampbell3_at_[hidden])
Date: 2002-08-11 07:10:59
Some of the advantages of shared_ptr gc are:
1) recovery resources as soon as they become unreachable
2) diagnosis of dangling pointers (by the weak_ptr<T>::get return value)
Some of the advantages of conservative gc
(e.g. http://www.hpl.hp.com/personal/Hans_Boehm/gc/) are:
1) Lower memory overhead:
a) 1 mark flag per allocated object
b) whatever extra allocation overhead required
to traverse the heap.
2) Lower time overhead, i.e. each pointer assignment
doesn't update at least 2 reference count values
(in the case of weak_ptr::operator= )
or sometime 4 reference count values
(in the case of shared_ptr::operator=).
The advantage of shared_ptr immediate recovery is especially
important when an unreachable object contains a scarce resource
such as file handle or database access.
I'm proposing that a compromise be implemented that combines
the advantages of both. More specifically, just retain the
strong reference count and let the conservative collector recover
memory. That way, only the strong reference count needs updating.
When it drops to 0, the resources (other than memory) are released
by a call to the objects DTOR. The memory recovery is delayed
by the conservative collector until it's actually needed.
Comments about gotcha's or other advantages and disadvantages
welcome.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk