30 messages in com.mysql.lists.plusplusRe: Eyeballs needed on new reference ...
FromSent OnAttachments
Warren Young14 Aug 2007 23:26 
Chris Frey15 Aug 2007 01:14 
Alex Burton15 Aug 2007 01:42 
Joseph Artsimovich15 Aug 2007 01:56 
Joel Fielder15 Aug 2007 02:29 
Robert Mecklenburg15 Aug 2007 07:47 
Graham Reitz15 Aug 2007 08:38 
Graham Reitz15 Aug 2007 08:47 
Graham Reitz15 Aug 2007 09:03 
Jonathan Wakely15 Aug 2007 15:06 
Warren Young16 Aug 2007 01:55 
Warren Young16 Aug 2007 02:23 
Warren Young16 Aug 2007 02:31 
Warren Young16 Aug 2007 02:57 
Warren Young16 Aug 2007 03:08 
Warren Young16 Aug 2007 03:11 
Jonathan Wakely17 Aug 2007 17:54 
Jonathan Wakely17 Aug 2007 18:00 
Warren Young20 Aug 2007 12:09 
Warren Young29 Nov 2007 00:04 
Joseph Artsimovich29 Nov 2007 04:20 
Warren Young29 Nov 2007 05:48 
Jonathan Wakely29 Nov 2007 17:40 
Jonathan Wakely29 Nov 2007 17:58 
Jonathan Wakely29 Nov 2007 18:15 
Warren Young30 Nov 2007 22:24 
Warren Young30 Nov 2007 22:35 
Warren Young30 Nov 2007 22:38 
Warren Young17 Dec 2007 05:53 
Jonathan Wakely17 Dec 2007 12:39 
Subject:Re: Eyeballs needed on new reference counted pointer template
From:Jonathan Wakely (mys@kayari.org)
Date:11/29/2007 05:40:06 PM
List:com.mysql.lists.plusplus

On 29/11/2007, Warren Young <mysq@etr-usa.com> wrote:

Jonathan Wakely wrote:

...safe against self-assignment...

I don't see any checks for self-assignment in your code. It sort of happens implicitly in assign(const ThisType&) because the refcount just goes up and then comes right back down, but this is wasteful. And in

No! :) Yes it happens implicitly, that's precisely the point. How many times does self-assignment happen? Seriously. It is almost always the result of a programming error, or maybe occasionally setting a collection of objects to a single value which happens to be in the collection _occasionally_ - let's generously assume it's 0.1% of all assignments. If it does happen, and your class isn't safe for self-assignment, very bad things happen. Nasal demons and all sorts. So we've all learnt to prevent that. But checking if (this ==&rhs) on *every* assignment is what's really wasteful. In 99.9% of assignments the rhs.use_count() goes up, and this->use_count() goes down. It's only wasteful in the 0.1% of cases where this == &rhs and the same refcount goes up and down. So by putting the explicit check back you've helped that tiny fraction of cases, at the expense of the common case. Providing an O(1) nothrow swap, and implementing the assignment operator in terms of copy and swap is the canonical assignment operator. And in The Future (cue sci-fi music) will be even more efficient thanks to rvalue-references and move-semantics.

the assign(T*) case, I'm pretty sure assigning the same pointer will result in a double-delete. I've added explicit checks to both assign() overloads.

Pleeeeeease remove it :)

Jon