472,145 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

What is "Handle Count"

109 100+
Im just wondering what the term Handle count means?
Aug 11 '08 #1
8 13582
Banfa
9,065 Expert Mod 8TB
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.
Aug 11 '08 #2
SpecialKay
109 100+
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.
Aug 11 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
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.
Aug 11 '08 #4
Banfa
9,065 Expert Mod 8TB
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.
Aug 11 '08 #5
SpecialKay
109 100+
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?
Aug 11 '08 #6
weaknessforcats
9,208 Expert Mod 8TB
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.
Aug 12 '08 #7
SpecialKay
109 100+
how would someone see this variable? I assue it is built in to VS?
Aug 12 '08 #8
oler1s
671 Expert 512MB
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.
Aug 12 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Rabun | last post: by
5 posts views Thread by Grant Edwards | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.