What is "Handle Count"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SpecialKay
    New Member
    • Mar 2008
    • 109

    What is "Handle Count"

    Im just wondering what the term Handle count means?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    The count of the number of handles or possibly the count of the number of references to the object acessed via the handle.

    Perhaps you could provide some context.

    Comment

    • SpecialKay
      New Member
      • Mar 2008
      • 109

      #3
      i was just looking for a general meaning. Im looking at some code that is using windows threads. The person that wrote the code said that everytime they call the function abc() they run it on a new thread, and the Handler Count increases. for some reason, this was not expected. They believe that the Handler Count should not have have increased, or should have increased much less then i accually did.
      I was not fimilar with the term.
      Judging by your definition, it sound to me like the Handler Count increasing is normal. Unfortunatly i dont have more details me self, but i will inquire just how much of an increase we are talking about.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        When you are inside a function that receives a pointer argument and you need to change the address in the pointer, then you need to delete the memory at the address in the pointer, allocte your new stuff and put the new address in the pointer.

        You can't tell from a pointer if:
        a) the address in the pointer is to a variable on the stack. If it is and you delete, you crash.
        b) the address in the pointer is to a varible on the heap. If it is and you delete, then any copies of that pointer (like in the calling function) are invalid. When you use them, you crash.

        So the only safe way to delete a pointer is a) it points to a heap variable and b) you have the last copy of that pointer.

        That means, in C, you have to manually keep track of the number of copies of a given pointer. That is, when you call a function, you increment the count. As you leave the function, you decrement the count.The combination of the pointer and the count is called a handle. These would be in a struct.

        The count is called a handle (or reference) count.

        In C++, you use a handle class: http://bytes.com/forum/thread651599.html.

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          The truth is SpecialKay that handle and handler are very generic terms and their meaning will be and how they are used will be entire dependent on the context they are used in.

          In the most generic terms

          A handle is an identifier that uniquely identifies some object in a given context without actually allowing direct access to it.

          A handler is a piece of code that is run in response to a specific event or message.

          Comment

          • SpecialKay
            New Member
            • Mar 2008
            • 109

            #6
            so the handle count would be refering to the number of pointers to the variables on each thread. and it would be normal for the handle count to increase. However this handle count, should decrease when the thread is finished. And at the end of the program, the handle count should be 0 otherwise we have a memory leak?

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              Originally posted by SpecialKay
              so the handle count would be refering to the number of pointers to the variables on each thread. and it would be normal for the handle count to increase. However this handle count, should decrease when the thread is finished. And at the end of the program, the handle count should be 0 otherwise we have a memory leak?
              That is correct. It is precisely this logic that allows leak detection software to work.

              Comment

              • SpecialKay
                New Member
                • Mar 2008
                • 109

                #8
                how would someone see this variable? I assue it is built in to VS?

                Comment

                • oler1s
                  Recognized Expert Contributor
                  • Aug 2007
                  • 671

                  #9
                  how would someone see this variable? I assue it is built in to VS?
                  VS? Handles are a generic programming concept, they have nothing to do with IDEs or Visual Studio. Whether you can see the internal counter depends entirely on how it is exposed or if it is exposed. Without a specific context, API, and code, the most that can be done is talk about the generic concepts involved in handles. When we talk specifics, for example using the C Windows API to get a handle count for a process, we can refer you to http://msdn.microsoft.com/en-us/libr...14(VS.85).aspx.

                  Comment

                  Working...