From: Chuck Messenger (chuckm_at_[hidden])
Date: 2003-05-29 07:39:57
Peter Dimov wrote:
> Chuck Messenger wrote:
>>There is no sample program to compile/run, so I have to guess somewhat
>>at how to use this one.
> There is libs/smart_ptr/test/collector_test.cpp. You need to #define
OK - thanks. I'll give it a try...
> The basic idea of the algorithm is to keep track of all heap objects managed
> by a shared_ptr. When the collector is invoked, it can use this information,
> coupled with a memory scan in these heap blocks, to compute the reference
> counts that would have occured if not for the external shared_ptr instances
> that are unknown to the collector.
> Using the difference between the computed counts and the actual counts, the
> collector can infer which blocks are reachable (they have a larger real
Got it - clever! Thanks for the explanation.
> Greg's cyclic_ptr uses the same algorithm except that his code decrements
> the counts in place instead of maintaining a parallel count structure. It
> also uses x = x; assignments (a clever trick) to discover the pointer
> Both pointer discovery methods are flawed, although in different ways. :-)
> It is not possible to write a portable collector using this algorithm
> without compiler support.
> Another class of garbage collected smart pointers keeps track of every smart
> pointer _instance_ using a global registry (sp_collector.cpp keeps track of
> every _object_). The upside is perfect discovery. The downside is that every
> smart pointer copy incurs much larger overhead, esp. in multithreaded code
> where the central registry becomes a bottleneck.
Sure, it won't be useful in a context where you're really stressing the
system with garbage. But it has some nice advantages.
What is the status of sp_collector.cpp? It's distributed as part of
Boost right now. Is it intended to remain part of the shared_ptr
library? It sounds like it should suit my purposes quite well, after all...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk