Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Eyeballs needed on new reference counted pointer template

Eyeballs needed on new reference counted pointer template

2007-11-29       - By Warren Young

 Back
Reply:     1     2     3     4     5     6     7     8     9  

Jonathan Wakely wrote:
> Hi Warren, here's a modified RefCountedPointer, with the following changes:

Mostly applied as-is, with some changes detailed below.

You've now made it into the CREDITS file.  :)

> * Added a no-throwing swap operation.

Is there a good reason for this to be public?  Isn't it just an
implementation detail for assign()?

> (Should probably define a global
> swap(x, y) to use this member)

Why?

> * Safe bool idiom replaces operator bool and operator!

I was going to do this, but just yesterday I found the need in
RefCountedPointer for operator== and operator!= as well.  I can get that
and also implicit conversion to bool-like with operator void*.  The safe
bool article warns against it in part because it lets you say:

  RefCountedPointer<Foo> bar(new Foo);
  delete bar;

But *really*.  If one is so intent on shooting oneself in the foot....

The only time this should happen accidentally is when converting an
unmanaged pointer to a refcounted pointer and forgetting to remove the
deletes you previously needed.  Such a bug will show up the first time
you run the program as it results in a double-delete.  I've documented
the risk in the refman and am content to leave it at that.

The other warnings in the article about operator void* don't really
apply here.  RefCountedPointer _is_ a pointer after all.  It's perfectly
legitimate that you should be able to convert it to void*, unlike in the
example he gives where cin/cout have no pointerness to them.

Your safe-bool code may still make its way into MySQL++, because there
are other operator bools on classes that, like cin/cout also have no
pointerness to them.

> ...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
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.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:    http://lists.mysql.com/plusplus?unsub=mysql@(protected)