List:MySQL++« Previous MessageNext Message »
From:Chris Frey Date:August 15 2007 8:15am
Subject:Re: Eyeballs needed on new reference counted pointer template
View as plain text  
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

Thread
Eyeballs needed on new reference counted pointer templateWarren Young15 Aug
  • Re: Eyeballs needed on new reference counted pointer templateChris Frey15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • Re: Eyeballs needed on new reference counted pointer templateAlex Burton15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • Re: Eyeballs needed on new reference counted pointer templateJoseph Artsimovich15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateJonathan Wakely16 Aug
      • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
        • Re: Eyeballs needed on new reference counted pointer templateJonathan Wakely18 Aug
          • Re: Eyeballs needed on new reference counted pointer templateJonathan Wakely18 Aug
          • Re: Eyeballs needed on new reference counted pointer templateWarren Young20 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • RE: Eyeballs needed on new reference counted pointer templateJoel Fielder15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • Re: Eyeballs needed on new reference counted pointer templateRobert Mecklenburg15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateGraham Reitz15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateGraham Reitz15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • Re: Eyeballs needed on new reference counted pointer templateGraham Reitz15 Aug