How to implement reference counting with 'Smart_ptr'?

This is a discussion on How to implement reference counting with 'Smart_ptr'? within the C++ Programming forums, part of the General Programming Boards category; Could anybody let me know where to find the source code (or sample code) of smart_ptr for reference counting? I ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    How to implement reference counting with 'Smart_ptr'?

    Could anybody let me know where to find the source code (or sample code) of smart_ptr for reference counting?
    I find the code for auto_ptr, but seems auto_ptr is not a REAL reference counting because it does not 'count'.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    auto_ptr is a smart pointer, not a reference counting smart pointer. Check out boost (boost.org). They have a smart pointer library that includes shared_ptr, which is a reference counting smart pointer. In fact, shared_ptr and many of the other boost smart pointers have been added to TR1 which is an almost standard C++ library.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,269
    Or take a look at CountedPtr from here:
    http://www.josuttis.com/
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    Use boost shared pointer or intrusive pointer.

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 error while linking..help
    By rapture in forum C++ Programming
    Replies: 4
    Last Post: 12-04-2007, 03:54 AM
  3. const reference formal arguments
    By Chaplin27 in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2004, 10:12 PM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  5. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM

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