Smart Pointer library in C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allerdyce.John@gmail.com

    #1

    Smart Pointer library in C++

    I think Smart Pointer library in C++ is implemented using reference
    count.
    How does smart pointer library detect if there is a circular
    reference? and if yes, what does it do about it?

    Thank you.

  • Luke Meyers

    #2
    Re: Smart Pointer library in C++

    Allerdyce.John@ gmail.com wrote:[color=blue]
    > I think Smart Pointer library in C++ is implemented using reference
    > count.
    > How does smart pointer library detect if there is a circular
    > reference? and if yes, what does it do about it?[/color]

    What library are you referring to? There is no standard smart pointer
    library for C++. The only thing that's even close is std::auto_ptr,
    which does not use refcounts because it transfers ownership on copy.

    Maybe you're referring to boost::shared_p tr? If so, that's off-topic
    here, but to briefly answer your question: it doesn't detect cycles,
    it's up to the programmer to keep that from happening. Cycle detection
    would be a property of a full-scale GC system, more overhead than I'm
    willing to accept from a comparatively lightweight smart pointer type.

    If you're curious about the implementation details, just go read
    boost/shared_ptr.hpp.

    Luke

    Comment

    • Kai-Uwe Bux

      #3
      Re: Smart Pointer library in C++

      Luke Meyers wrote:
      [color=blue]
      > Allerdyce.John@ gmail.com wrote:[color=green]
      >> I think Smart Pointer library in C++ is implemented using reference
      >> count.
      >> How does smart pointer library detect if there is a circular
      >> reference? and if yes, what does it do about it?[/color]
      >
      > What library are you referring to? There is no standard smart pointer
      > library for C++. The only thing that's even close is std::auto_ptr,
      > which does not use refcounts because it transfers ownership on copy.[/color]

      Well, there is tr1::shared_ptr , formerly known as boost::shared_p tr.

      [color=blue]
      > Maybe you're referring to boost::shared_p tr? If so, that's off-topic
      > here[/color]
      [snip]

      I beg to differ: Boost libraries are the most canonical candidates for
      standardization . Thus, they are directly relevant to "planned extensions
      and adjustments" as mentioned in the FAQ:

      Only post to comp.lang.c++ if your question is about the C++ language
      itself. For example, C++ code design, syntax, style, rules, bugs, etc.
      Ultimately this means your question must be answerable by looking into the
      C++ language definition as determined by the ISO/ANSI C++ Standard
      document, and by *planned extensions and adjustments*. (Emphasis added)

      The fact that boost::shared_p tr now is in tr1 illustrates this point.

      Also, Boost libraries, which strive to be as platform independent as
      possible, have been by and large regarded topical on this news group for
      quite some time.


      Best

      Kai-Uwe Bux

      Comment

      • P.J. Plauger

        #4
        Re: Smart Pointer library in C++

        "Kai-Uwe Bux" <jkherciueh@gmx .net> wrote in message
        news:dr1stg$qn0 $1@murdoch.acc. Virginia.EDU...
        [color=blue]
        > Luke Meyers wrote:
        >[color=green]
        >> Allerdyce.John@ gmail.com wrote:[color=darkred]
        >>> I think Smart Pointer library in C++ is implemented using reference
        >>> count.
        >>> How does smart pointer library detect if there is a circular
        >>> reference? and if yes, what does it do about it?[/color]
        >>
        >> What library are you referring to? There is no standard smart pointer
        >> library for C++. The only thing that's even close is std::auto_ptr,
        >> which does not use refcounts because it transfers ownership on copy.[/color]
        >
        > Well, there is tr1::shared_ptr , formerly known as boost::shared_p tr.
        >
        >[color=green]
        >> Maybe you're referring to boost::shared_p tr? If so, that's off-topic
        >> here[/color]
        > [snip]
        >
        > I beg to differ: Boost libraries are the most canonical candidates for
        > standardization . Thus, they are directly relevant to "planned extensions
        > and adjustments" as mentioned in the FAQ:
        >
        > Only post to comp.lang.c++ if your question is about the C++ language
        > itself. For example, C++ code design, syntax, style, rules, bugs, etc.
        > Ultimately this means your question must be answerable by looking into
        > the
        > C++ language definition as determined by the ISO/ANSI C++ Standard
        > document, and by *planned extensions and adjustments*. (Emphasis added)
        >
        > The fact that boost::shared_p tr now is in tr1 illustrates this point.
        >
        > Also, Boost libraries, which strive to be as platform independent as
        > possible, have been by and large regarded topical on this news group for
        > quite some time.[/color]

        I basically agree. The interesting issue for the Off Topic Police is to
        determine whether a Technical Report developed by WG21 and approved by
        ISO as an extension to Standard C++ is still off topic because it's a
        non-normative document. Gonna be hard to learn about all the goodies in
        TR1 (which, as you say, are all candidates for inclusion in C++0X) if
        we can't discuss them in more-or-less polite company.

        P.J. Plauger
        Dinkumware, Ltd.



        Comment

        • Axter

          #5
          Re: Smart Pointer library in C++

          Allerdyce.John@ gmail.com wrote:[color=blue]
          > I think Smart Pointer library in C++ is implemented using reference
          > count.
          > How does smart pointer library detect if there is a circular
          > reference? and if yes, what does it do about it?
          >
          > Thank you.[/color]

          If I'm not mistaken, the boost::week_ptr is suppose to be used to help
          stop circular reference with the boost::shared_p tr

          Comment

          • Default User

            #6
            Re: Smart Pointer library in C++

            P.J. Plauger wrote:

            [color=blue]
            > I basically agree. The interesting issue for the Off Topic Police is
            > to determine whether a Technical Report developed by WG21 and
            > approved by ISO as an extension to Standard C++ is still off topic
            > because it's a non-normative document. Gonna be hard to learn about
            > all the goodies in TR1 (which, as you say, are all candidates for
            > inclusion in C++0X) if we can't discuss them in more-or-less polite
            > company.[/color]


            "Candidates for" doesn't mean standard. I don't have much objection to
            discussing what's in the TR and how the features might be used if the
            TR is incorporated into the revised standard (although such discussion
            might be better on comp.std.c++).

            My objection with Boost has always been people just recommending it
            without noting its non-standard nature. There are people working in C++
            who can't just use any old third-party library they want. As nifty keen
            as Boost is, until it's actually in a standard library that's its
            status as well.

            When the TR came out, I dropped my objections for the most part.


            Brian

            Comment

            • Axter

              #7
              Re: Smart Pointer library in C++

              Default User wrote:[color=blue]
              > P.J. Plauger wrote:
              >
              >[color=green]
              > > I basically agree. The interesting issue for the Off Topic Police is
              > > to determine whether a Technical Report developed by WG21 and
              > > approved by ISO as an extension to Standard C++ is still off topic
              > > because it's a non-normative document. Gonna be hard to learn about
              > > all the goodies in TR1 (which, as you say, are all candidates for
              > > inclusion in C++0X) if we can't discuss them in more-or-less polite
              > > company.[/color]
              >
              >
              > "Candidates for" doesn't mean standard. I don't have much objection to
              > discussing what's in the TR and how the features might be used if the
              > TR is incorporated into the revised standard (although such discussion
              > might be better on comp.std.c++).
              >
              > My objection with Boost has always been people just recommending it
              > without noting its non-standard nature. There are people working in C++
              > who can't just use any old third-party library they want. As nifty keen
              > as Boost is, until it's actually in a standard library that's its
              > status as well.
              >
              > When the TR came out, I dropped my objections for the most part.[/color]

              I object to not being able to talk about the boost library in general,
              because currently the normal track for getting new candidates for the
              standard, is to first have it added to the boost library, and after a
              good review, and usage, then it's considered for TR and then for the
              official standard.
              If you cut off talking about boost, you're killing potential inputs to
              the standard, and you're possibly killing potentially good review and
              critiques for candidates to the language.

              I also don't think you should have to put a disclaimer every time you
              make a post referring to the boost library.
              IMHO, this is common enough knowledge that the user should already know
              he/she is being referred to non-STL code.

              IMHO, if topic-police posters think the disclaimer needs to be added,
              than let them added themselves.

              Comment

              • Default User

                #8
                Re: Smart Pointer library in C++

                Axter wrote:

                [color=blue]
                > I object to not being able to talk about the boost library in general,
                > because currently the normal track for getting new candidates for the
                > standard, is to first have it added to the boost library, and after a
                > good review, and usage, then it's considered for TR and then for the
                > official standard.
                > If you cut off talking about boost, you're killing potential inputs to
                > the standard, and you're possibly killing potentially good review and
                > critiques for candidates to the language.[/color]

                Shouldn't those discussions take place on comp.std.c++?
                [color=blue]
                > I also don't think you should have to put a disclaimer every time you
                > make a post referring to the boost library.[/color]

                Why not?
                [color=blue]
                > IMHO, this is common enough knowledge that the user should already
                > know he/she is being referred to non-STL code.[/color]

                Most of the people who get references to Boost have little knowledge
                about what is and is not standard.
                [color=blue]
                > IMHO, if topic-police posters think the disclaimer needs to be added,
                > than let them added themselves.[/color]

                For the most part, the topic police tend to be staring up at that
                clouds and whistling a happy tune with Boost roars down the street.
                There are a few of us who object, but as I said I've more given up on
                mere referrals.



                Brian

                Comment

                • Axter

                  #9
                  Re: Smart Pointer library in C++

                  Default User wrote:[color=blue]
                  > Axter wrote:
                  >
                  >[color=green]
                  > > I object to not being able to talk about the boost library in general,
                  > > because currently the normal track for getting new candidates for the
                  > > standard, is to first have it added to the boost library, and after a
                  > > good review, and usage, then it's considered for TR and then for the
                  > > official standard.
                  > > If you cut off talking about boost, you're killing potential inputs to
                  > > the standard, and you're possibly killing potentially good review and
                  > > critiques for candidates to the language.[/color]
                  >
                  > Shouldn't those discussions take place on comp.std.c++?[/color]

                  Yes, but there's a limited feedback on the comp.std.c++, and a long lag
                  time between discussions since the group is moderated.
                  What may take a few hours here, takes a few days to discuss there.

                  Comment

                  • Luke Meyers

                    #10
                    Re: Smart Pointer library in C++

                    Kai-Uwe Bux wrote:[color=blue]
                    > Luke Meyers wrote:
                    > Well, there is tr1::shared_ptr , formerly known as boost::shared_p tr.
                    >[color=green]
                    > > Maybe you're referring to boost::shared_p tr? If so, that's off-topic
                    > > here[/color]
                    >
                    > I beg to differ: Boost libraries are the most canonical candidates for
                    > standardization . Thus, they are directly relevant to "planned extensions
                    > and adjustments" as mentioned in the FAQ:[color=green]
                    > >snip<[/color]
                    > The fact that boost::shared_p tr now is in tr1 illustrates this point.[/color]

                    Fair point. What I was really trying to point out was that the OP did
                    not make it clear what the hell smart pointer type was being referred
                    to.
                    [color=blue]
                    > Also, Boost libraries, which strive to be as platform independent as
                    > possible, have been by and large regarded topical on this news group for
                    > quite some time.[/color]

                    Marvelous. I like Boost, after all.

                    Luke

                    Comment

                    • Default User

                      #11
                      Re: Smart Pointer library in C++

                      Axter wrote:
                      [color=blue]
                      > Default User wrote:[/color]
                      [color=blue][color=green]
                      > > Shouldn't those discussions take place on comp.std.c++?[/color]
                      >
                      > Yes, but there's a limited feedback on the comp.std.c++, and a long
                      > lag time between discussions since the group is moderated.
                      > What may take a few hours here, takes a few days to discuss there.[/color]

                      That's fine. It should be noted that I don't believe I've ever objected
                      to a discussion of what might be comin' down the pike. My own grumbles
                      were due to people suggesting Boost as solutions to problems presented
                      here without clarifying the nature of the solution.



                      Brian

                      Comment

                      Working...