What is a handle?

Source: Internet
Author: User

What is the handle? This problem has plagued me since I learned VC. Recently I found a good answer from Microsoft's book windows core programming, the answers previously found in Baidu, googo, and other search engines were not satisfactory. Everyone interpreted the handle as a pointer and identified an object. In fact, this understanding is not completely correct.

Now, the structure of the handle table is as follows:

 

We know that when a process is initialized, the system will allocate a handle table to it. This handle table is only used by kernel objects and is not applicable to user objects, any function used to create a kernel object will return a process-related handle, which can be used by all threads running in the same process, the system uses indexes to identify the location where the kernel object information is stored in the Process Handle table. To obtain the actual index value, you need a handle. In most operating systems, the relationship between the handle and the index is to shift the handle value to the right by two places.

Therefore, we usually say that the handle identifies an object. There is no error in this sentence. If it is a pointer, there will be problems, because we use the handle of an object to obtain the index of the object in the handle table, and finally get the address of the object in the memory, that is, the pointer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.