EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  <20092010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  <20092010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: About the reference counting in GDD smart pointer
From: "Jeff Hill" <[email protected]>
To: "'Andrew Johnson'" <[email protected]>
Cc: [email protected], "'Core-Talk'" <[email protected]>
Date: Tue, 1 Sep 2009 09:25:23 -0600
> Why not add a gdd factory method to the smartGDDPointer API, so the user
> never needs to do a 'new gdd' themselves?
> 
> smartGDDPointer pDD1;	// Empty
> pDD1.newGdd();		// Create one
	
I did mention, in my message, that a factory was the first option. 

I suspect that we can all agree (based on the advantage of hindsight) that a factory producing a smart pointer would have been a better design. The controversy arises when considering what to do about the reference and un-reference interface in gdd, which appears to be somewhat broken by modern convention. In Jim's defense - some time has passed since he implemented the gdd interface, and I added a smart pointer a few years after gdd was written. The controversy arises, of course, surrounding changing the gdd interface which is in use.

Unfortunately, unless one removes referencing, and also new, from the gdd interface, then this still does not prevent someone from inadvertently doing this. This type of unfortunate pitfall is what Alex and others have experienced - and complained about.

gdd * pGDD = new gdd();
...
smartGDDPointer pDD1;	// Empty
pDD1.newGdd(); //create 1st one
...
smartGDDPointer pDD1 = pGDD; // replace with 2nd, woops forgot to call pGDD->unreferenced()

Admittedly, adding the factory, but not amending the gdd interface (maybe in sum what you are advocating) might be slightly safer because the user would be better guided into a mainstream usage pattern.

BTW: Is there a reason why you have a preference:
// this
smartGDDPointer pDD1;	// Empty
pDD1.newGdd();		// Create one
// versus this (what I would probably implement lacking further input)
smartGDDPointer pDD1 = gdd :: factory (); // Create one

A messy aspect of factories is that one must replicate all of the various ctor signatures for the various modes of the target. I think that there are six of them with gdd. Maybe not so bad.

Jeff
______________________________________________________
Jeffrey O. Hill           Email        [email protected]
LANL MS H820              Voice        505 665 1831
Los Alamos NM 87545 USA   FAX          505 665 5107

Message content: TSPA


> -----Original Message-----
> From: Andrew Johnson [mailto:[email protected]]
> Sent: Friday, August 28, 2009 11:56 AM
> To: Jeff Hill
> Cc: [email protected]; Core-Talk
> Subject: Re: About the reference counting in GDD smart pointer
> 
> Hi Jeff,
> 
> On Friday 28 August 2009 10:55:04 Jeff Hill wrote:
> >
> > Some options
> > ------------
> 
> Why not add a gdd factory method to the smartGDDPointer API, so the user
> never needs to do a 'new gdd' themselves?
> 
> smartGDDPointer pDD1;	// Empty
> pDD1.newGdd();		// Create one
> 
> > // the smart pointer maintains the ref count
> > smartGDDPointer pDD2 = pDD1;
> > smartGDDPointer pDD3 = pDD2;
> > pDD2 = pDD3;
> 
> - Andrew
> --
> The best FOSS code is written to be read by other humans -- Harold Welte



Replies:
Re: About the reference counting in GDD smart pointer Andrew Johnson
RE: About the reference counting in GDD smart pointer Alex . Chen
References:
About the reference counting in GDD smart pointer Alex . Chen
RE: About the reference counting in GDD smart pointer Jeff Hill
Re: About the reference counting in GDD smart pointer Andrew Johnson

Navigate by Date:
Prev: main trunk base build failure win32-x86 Jeff Hill
Next: Re: About the reference counting in GDD smart pointer Andrew Johnson
Index: 2002  2003  2004  2005  2006  2007  2008  <20092010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: About the reference counting in GDD smart pointer Andrew Johnson
Next: Re: About the reference counting in GDD smart pointer Andrew Johnson
Index: 2002  2003  2004  2005  2006  2007  2008  <20092010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Feb 2012 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·