Subj : Re: A question about atomic_ptr To : comp.programming.threads From : Peter Dimov Date : Wed Apr 13 2005 07:53 pm Joe Seigh wrote: > On Wed, 13 Apr 2005 15:41:01 +0300, Peter Dimov > wrote: >> Joe Seigh wrote: > ... >> I don't believe that C++ code can benefit from a traditional deferred >> counting scheme (which avoids counting the stack and the registers >> and only counts heap-allocated references.) >> >> Your local_ptr can possibly benefit from a deferring the counting >> somewhat, but I'm not sure whether it will be worth doing. >> >> Weighted reference counting is another interesting algorithm (on >> paper). I think that it is also not worth doing. The idea there is >> to keep a local count (weight) in each pointer. The pointer starts >> with 65536 (say) and on each copy the weight is shared between the >> source and the copy. When a pointer is destroyed its weight is >> subtracted from the reference count (its initial value is also >> 65536). > > To make pointers copyable you have to divide up the weight somehow. If you > divide by two, after as little as 16 copies, you resulting > pointer becomes uncopyable. I think that when you need to copy a source with weight 1, you can just increment the total weight by 65536 and create a weighted_ptr with a weight 65536, without modifying the source. Or you could also increase the source's weight to 65536 and increment the total weight by 65536+65535. > There's another weighted reference counting scheme that uses infinite > precision fractions for the weight. It keeps extending the precision at > the expense of space boundedness. Seems like overkill to me. ;-) > atomic_ptr/local_ptr is a modified weighted reference counting > scheme. local_ptr looks a lot like pure weighted reference counting. From looking at the source, local_ptr doesn't seem weighted to me. There is no weight member and copies just increment a shared reference count (the ephemeral count). But maybe I'm not looking at the latest version (the one on atomic-ptr-plus.sf.net is 0.0.2). .