30 messages in com.mysql.lists.plusplusRe: Eyeballs needed on new reference ...| From | Sent On | Attachments |
|---|---|---|
| Warren Young | 14 Aug 2007 23:26 | |
| Chris Frey | 15 Aug 2007 01:14 | |
| Alex Burton | 15 Aug 2007 01:42 | |
| Joseph Artsimovich | 15 Aug 2007 01:56 | |
| Joel Fielder | 15 Aug 2007 02:29 | |
| Robert Mecklenburg | 15 Aug 2007 07:47 | |
| Graham Reitz | 15 Aug 2007 08:38 | |
| Graham Reitz | 15 Aug 2007 08:47 | |
| Graham Reitz | 15 Aug 2007 09:03 | |
| Jonathan Wakely | 15 Aug 2007 15:06 | |
| Warren Young | 16 Aug 2007 01:55 | |
| Warren Young | 16 Aug 2007 02:23 | |
| Warren Young | 16 Aug 2007 02:31 | |
| Warren Young | 16 Aug 2007 02:57 | |
| Warren Young | 16 Aug 2007 03:08 | |
| Warren Young | 16 Aug 2007 03:11 | |
| Jonathan Wakely | 17 Aug 2007 17:54 | |
| Jonathan Wakely | 17 Aug 2007 18:00 | |
| Warren Young | 20 Aug 2007 12:09 | |
| Warren Young | 29 Nov 2007 00:04 | |
| Joseph Artsimovich | 29 Nov 2007 04:20 | |
| Warren Young | 29 Nov 2007 05:48 | |
| Jonathan Wakely | 29 Nov 2007 17:40 | |
| Jonathan Wakely | 29 Nov 2007 17:58 | |
| Jonathan Wakely | 29 Nov 2007 18:15 | |
| Warren Young | 30 Nov 2007 22:24 | |
| Warren Young | 30 Nov 2007 22:35 | |
| Warren Young | 30 Nov 2007 22:38 | |
| Warren Young | 17 Dec 2007 05:53 | |
| Jonathan Wakely | 17 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




