1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 <2009> 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 | Index | 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 <2009> 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 |
<== Date ==> | <== Thread ==> |
---|
Subject: | RE: About the reference counting in GDD smart pointer |
From: | "Jeff Hill" <[email protected]> |
To: | <[email protected]> |
Cc: | [email protected], "'tech-talk'" <[email protected]> |
Date: | Fri, 28 Aug 2009 09:55:04 -0600 |
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 Message content: TSPA From: [email protected]
[mailto:[email protected]]
|