From: Warren Young Date: August 16 2007 9:31am Subject: Re: Eyeballs needed on new reference counted pointer template List-Archive: http://lists.mysql.com/plusplus/6946 Message-Id: <46C41984.5060603@etr-usa.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Alex Burton wrote: > Slight improvements might be made by only testing counted_ to know if it > is a non null pointer instead of checking ref_ is set all the time. This is just paranoia, of the same sort that motivates some other posters in this thread to recommend zeroing the pointers in detach(). I think they're right to be paranoid, because it justifies my own paranoia. :) You never know when some bug will cause one pointer but not the other to be zeroed. If either is zero, we can't dereference the other, because it's not supposed to be used any more. An earlier iteration simplified all this by wrapping both the reference count and the T* in a structure, and RefCountedPointer actually managed a pointer to a structure of this type on the heap. It had the advantage of only one data member in RefCountedPointer itself, so only one thing to test, but it turned the single indirection of an unmanaged pointer into triple indirection. Too expensive...