Reference counting

Discussion in 'C++' started by oec.deepak@gmail.com, Jul 30, 2007.

  1. Guest

    Hi
    Cn any one telll me what is Reference counting in C++.
     
    , Jul 30, 2007
    #1
    1. Advertising

  2. * :
    > Hi
    > Cn any one telll me what is Reference counting in C++.
    >


    Not different from its usage in other languages.

    <url: http://en.wikipedia.org/wiki/Reference_counting>.


    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jul 30, 2007
    #2
    1. Advertising

  3. wrote:
    > Hi
    > Cn any one telll me what is Reference counting in C++.
    >


    Reference counting usually means that dynamically created objects
    maintain a "reference count" that counts the number of "owners" or said
    another way the number of times the reference count needs to be
    decremented so as to indicate to the last "owner" that it is responsible
    to dispose of the dynamically created object.

    Reference counted systems usually go hand in hand with "smart pointers"
    where each smart pointer contains an obligation of "ownership". The
    destructor and assignment operators of the "smart pointer" are
    overloaded so that when the smart pointer is deleted or assigned it will
    decrement the "reference count".

    This is a simplistic form of automated "garbage collection" but suffers
    a design constraint that there must be no loops in your "ownership
    graph" otherwise it will leak.

    There are many systems that employ a reference counting technique. e.g.
    Win32 COM has an abstract base class that an "AddRef()" and "Release()"
    method. Boost has a smart pointer that employs a reference count for
    you named "shared_ptr<>" and will be made part of the next revision of
    the C++ standard. You have Loki and Austria libraries that also employ
    smart pointers.

    In my experience, employing reference counting and smart pointers
    results in vast improvements software development.
     
    Gianni Mariani, Jul 30, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ash
    Replies:
    1
    Views:
    417
    SenderX
    Oct 24, 2003
  2. Kalle Rutanen

    Reference counting in C++

    Kalle Rutanen, May 7, 2005, in forum: C++
    Replies:
    0
    Views:
    561
    Kalle Rutanen
    May 7, 2005
  3. Tony Johansson

    reference counting

    Tony Johansson, May 22, 2005, in forum: C++
    Replies:
    4
    Views:
    371
    Andrew Koenig
    May 23, 2005
  4. mathieu
    Replies:
    8
    Views:
    511
    Juha Nieminen
    Aug 31, 2008
  5. edwardfredriks

    counting up instead of counting down

    edwardfredriks, Sep 6, 2005, in forum: Javascript
    Replies:
    6
    Views:
    206
    Dr John Stockton
    Sep 7, 2005
Loading...

Share This Page