Making a smart pointer which works with incomplete types

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James Kanze

    #46
    Re: Making a smart pointer which works with incomplete types

    On Sep 8, 6:29 pm, Juha Nieminen <nos...@thanks. invalidwrote:
    James Kanze wrote:
    In this case you have to always pay the price of a per-object
    deleter even if you don't use one.
    And what is that price?
    sizeof(T*) * amount_of_objec ts
    Maybe, maybe not. On a Sun Sparc, in 32 bit mode, the price is
    0. (Allocation granularity is 8 bytes, to ensure alignment of a
    double. The reference count is 4 bytes. There are thus 4 bytes
    leftover when it is allocated. Just the size of a T*.)

    --
    James Kanze (GABI Software) email:james.kan ze@gmail.com
    Conseils en informatique orientée objet/
    Beratung in objektorientier ter Datenverarbeitu ng
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

    Comment

    • Juha Nieminen

      #47
      Re: Making a smart pointer which works with incomplete types

      James Kanze wrote:
      Maybe, maybe not. On a Sun Sparc, in 32 bit mode, the price is
      0. (Allocation granularity is 8 bytes, to ensure alignment of a
      double. The reference count is 4 bytes. There are thus 4 bytes
      leftover when it is allocated. Just the size of a T*.)
      Question: Will shared_ptr in the new standard support user-defined
      custom allocators for the smart pointer to allocate its data?

      Comment

      • James Kanze

        #48
        Re: Making a smart pointer which works with incomplete types

        On Sep 9, 5:13 pm, Juha Nieminen <nos...@thanks. invalidwrote:
        James Kanze wrote:
        Maybe, maybe not. On a Sun Sparc, in 32 bit mode, the price is
        0. (Allocation granularity is 8 bytes, to ensure alignment of a
        double. The reference count is 4 bytes. There are thus 4 bytes
        leftover when it is allocated. Just the size of a T*.)
        Question: Will shared_ptr in the new standard support
        user-defined custom allocators for the smart pointer to
        allocate its data?
        I hope not. Too much added complexity for too little benefit.

        --
        James Kanze (GABI Software) email:james.kan ze@gmail.com
        Conseils en informatique orientée objet/
        Beratung in objektorientier ter Datenverarbeitu ng
        9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

        Comment

        • Kai-Uwe Bux

          #49
          Re: Making a smart pointer which works with incomplete types

          James Kanze wrote:
          On Sep 9, 5:13 pm, Juha Nieminen <nos...@thanks. invalidwrote:
          >James Kanze wrote:
          Maybe, maybe not. On a Sun Sparc, in 32 bit mode, the price is
          0. (Allocation granularity is 8 bytes, to ensure alignment of a
          double. The reference count is 4 bytes. There are thus 4 bytes
          leftover when it is allocated. Just the size of a T*.)
          >
          >Question: Will shared_ptr in the new standard support
          >user-defined custom allocators for the smart pointer to
          >allocate its data?
          >
          I hope not. Too much added complexity for too little benefit.
          The draft n2691 has an allocator for shared_ptr. Interestingly, I did not
          find a get_allocator() function.


          Best

          Kai-Uwe Bux

          Comment

          • Pete Becker

            #50
            Re: Making a smart pointer which works with incomplete types

            On 2008-09-10 03:30:50 -0400, James Kanze <james.kanze@gm ail.comsaid:
            On Sep 9, 5:13 pm, Juha Nieminen <nos...@thanks. invalidwrote:
            >James Kanze wrote:
            >>Maybe, maybe not. On a Sun Sparc, in 32 bit mode, the price is
            >>0. (Allocation granularity is 8 bytes, to ensure alignment of a
            >>double. The reference count is 4 bytes. There are thus 4 bytes
            >>leftover when it is allocated. Just the size of a T*.)
            >
            >Question: Will shared_ptr in the new standard support
            >user-defined custom allocators for the smart pointer to
            >allocate its data?
            >
            I hope not. Too much added complexity for too little benefit.
            It's there, and the complexity in the specification isn't bad, because
            the allocator isn't part of the type. There's an additional constructor
            that takes an extra argument that specifies an allocator, an additional
            overload of reset() that also takes an extra argument, and a new
            non-member template function, allocate_shared , that takes an allocator.

            --
            Pete
            Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
            Standard C++ Library Extensions: a Tutorial and Reference
            (www.petebecker.com/tr1book)

            Comment

            • Pete Becker

              #51
              Re: Making a smart pointer which works with incomplete types

              On 2008-09-10 08:06:34 -0400, Kai-Uwe Bux <jkherciueh@gmx .netsaid:
              >
              The draft n2691 has an allocator for shared_ptr. Interestingly, I did not
              find a get_allocator() function.
              The type of the allocator isn't part of the type, so a get_allocator
              function would have to be the same sort of abomination as get_deleter:
              if you guess the type correctly, you get a pointer to the object,
              otherwise a null pointer.

              --
              Pete
              Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
              Standard C++ Library Extensions: a Tutorial and Reference
              (www.petebecker.com/tr1book)

              Comment

              Working...