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: [email protected]
To: "Jeff Hill" <[email protected]>
Cc: [email protected], "'tech-talk'" <[email protected]>
Date: Mon, 31 Aug 2009 11:12:02 +0800

Jeff,

Personally, I'd prefer the removal of the reference() and unreference() from the GDD's public interface and a compile-time error for legacy application code. But, yes I totally understand your concern about the unexpected cost caused to users who already used GDD in a strange way. The comments in the smartGDDPointer.h will be helpful, besides I think adding a section about how to use the GDD smart pointers correctly to the GDD User's Guide or GDD Reference Manual will be more helpful because these documents are the entry points for users to understand what GDD is.

Thanks,

Alex



From: "Jeff Hill" <[email protected]>
To: <[email protected]>
Cc: [email protected], "'tech-talk'" <[email protected]>
Date: 2009-08-29 12:27 AM
Subject: RE: About the reference counting in GDD smart pointer
Sent by: [email protected]





Hi Alex,
 
Ø  my opinion, the init() called by the gdd constructors shouldn't place the reference count to 1 (it should be initialized instead to zero)
 
Hopefully I can explain this situation with some historical background. Originally, when Jim Kowalkoski wrote gdd he set the reference count to one in the gdd constructor. It was intended by Jim to be used like this.
 
Gdd * pDD0 = new gdd;
Gdd * pDD1 = pDD0;
pDD0->unreferenced ();

pDD1->unreference ();
 
After using this for awhile one realizes that manual maintenance of the reference count is very error prone, and that a smart pointer is a better way. We still have to  un-reference the gdd once when installing it into the smart pointer, but after that there are no worries.
 
// be careful to unreference here
Gdd * pDD0 = new gdd;
smartGDDPointer pDD1 (pDD0);
pDD0->unreferenced ();
 
// from here on down the smart pointer maintains the reference count
smartGDDPointer pDD2 = pDD1;
smartGDDPointer pDD3 = pDD2;
pDD2 = pDD3;
 
We have to be careful about changing the original behavior of GDD because there is legacy code. Changing behavior, so that the reference count is initialized to zero, and not one, when the gdd is created will break lots of preexisting code in the worst kind of way where problems might be discovered by end users at runtime. I don’t mind changing the code that I maintain, but there is quite a bit of application level code that is maintained in the community.
 
Some options
------------------
 
1)      One option would be to remove reference, and unreference from GDD’s public interface. These might be replaced by a factory that returns a smart pointer. This would not be backwards compatible, but at least we would feel confident that legacy code would not compile until it is adjusted. We prefer compile time bugs to runtime bugs of course. Probably the only downside is an unexpected cost for upgrading users who find that they have to recode when they get a new version.
2)      Do nothing. The current situation isn’t perfect but we would prefer to use the dataAccess library alternative in the future so perhaps we should leave GDD unmodified.
 
What do you think? I am also open to alternative suggestions that you might have?
 
I added this comment to smartGDDPointer.h
 
//
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// // be careful to manually unreference here
// // (the reference count is initialized to one by the gdd ctor)
// Gdd * pDD0 = new gdd;
// smartGDDPointer pDD1 (pDD0);
// pDD0->unreference ();
//
// // from here on down the smart pointer maintains the ref count
// smartGDDPointer pDD2 = pDD1;
// smartGDDPointer pDD3 = pDD2;
// pDD2 = pDD3;
//
 
PS: In R3.14.11 there are several fixes coming for various issues in the PCAS library. The details are in the mantis bug tracking system.
 
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
 
From: [email protected] [mailto:[email protected]]
Sent:
Friday, August 28, 2009 2:55 AM
To:
Jeff Hill
Cc:
[email protected]
Subject:
About the reference counting in GDD smart pointer

 

Hey Jeff,


I think the GDD smart pointer is a little bit weird, in a common way to use smart pointers as follows:


{

   smartGDDPointer sGDDPtr=new gdd();

}


the newly allocated gdd object isn't freed when sGDDPtr is out of scope. If you want to use smartGDDPointer as a normal smart pointer, you must place a line code immediately below the new operator, like this:


{

   smartGDDPointer sGDDPtr=new gdd();

   //The reference count of the newly created gdd object is actually 2 at this time.
   //The gdd() places the reference count to 1, and the assignment operator increase it to 2.

   sGDDPtr->unreference();

}


We see that smartGDDPointer is the intrusive type of smart pointer, the gdd has one reference count member and two functions reference() and unreference(). In my opinion, the init() called by the gdd constructors shouldn't place the reference count to 1, the reference counting shouldn't be carried out by gdd itself. smartGDDPointer is the manager of the gdd object and the only guy who can operate the reference() and unreference() on gdd object


Thanks,

Alex



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

Navigate by Date:
Prev: Re: About the reference counting in GDD smart pointer Andrew Johnson
Next: RE: Status PV Gateway fixes/changes from Jeff Hill Jeff Hill
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 Alex . Chen
Next: RE: Status PV Gateway fixes/changes from Jeff Hill Jeff Hill
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 ·