Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: Eyeballs needed on new reference counted pointer template

From: Chris Frey <cdfrey(at)foursquare.net>
Date: Wed Aug 15 2007 - 04:15:08 EDT


On Wed, Aug 15, 2007 at 12:27:18AM -0600, Warren Young wrote:
> Smart pointers are tricky, and automatic memory management is even
> trickier, and I just created a template that does both. I swapped it in
> for existing code in MySQL++ that used value semantics and it passes the
> test suite, but I'd still appreciate someone else taking a look at it.
>
> http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/refcounted.h?view=markup

Just some nit-pick comments. :-)

	void assign(T* c)
	{
		detach();

		if (c) {
			counted_ = c;
			refs_ = new size_t(1);
		}
		else {
			counted_ = 0;
			refs_ = 0;
		}
	}

In a very rare case, the call to:

        assign(new SomeObject);

will leak memory if the new size_t(1) runs out of memory and throws an exception.

Also, I'm more paranoid, and would probably zero the pointers in detach() anyway, just in case of that new exception.

Although if new throws, we have bigger problems to worry about. :-) I usually don't even bother catching out of memory exceptions. But a library probably shouldn't leak, in case there are people who do catch out-of-mem.

  • Chris
-- 
MySQL++ Mailing List
For list archives: 
http://lists.mysql.com/plusplus
To unsubscribe:    
http://lists.mysql.com/plusplus?unsub=lists@pantek.com
Received on Wed Aug 15 04:15:24 2007

This archive was generated by hypermail 2.1.8 : Sun Oct 07 2007 - 10:03:00 EDT

Do you need help?X

Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library