Reference Counting

This is a discussion on Reference Counting within the C++ Programming forums, part of the General Programming Boards category; I can't understand the concept behind reference counting! When and why an object is called reference counted? Is it some ...

  1. #1
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602

    Reference Counting

    I can't understand the concept behind reference counting!

    When and why an object is called reference counted?

    Is it some kind of handler, like HWND, HDC etc?

    Any info would be appreciated!
    Devoted my life to programming...

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,973
    You might want to search the Web concerning "reference counting". Simply put, the idea is to track the (number of) pointers that refer to (and own) an object, usually so that the object can be destroyed when the last such pointer no longer refers to it.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    By way of example, often string classes contain a shared ptr to the data (actual characters) so things that just copy the object don't copy the data too. Only two conditions result in alteration or deletion of the string data: destruction of the final object referencing that data and if any of the string objects related to that data try to alter it (which results in the string being copied first, then altered so the original remains intact). The point of doing this is reducing memory consumption and at the same time speeding program execution, albeit only slightly.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    Oh, i think i get the basic idea, but i'll search it a bit to learn more about it.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21