Differences between handle and pointer

Source: Internet
Author: User

The handle is actually a pointer to a certain resource, but it is different from the pointer: the pointer corresponds to a data address in the memory, and the pointer can be freely modified. Windows does not want a general program to modify its internal data structure, because it is too insecure. Therefore, Windows assigns a handle to each memory area declared by using functions such as globalalloc (essentially a pointer, but do not operate on it directly ), generally, you only use this handle to specify the memory to operate when calling an API function. When you need to perform direct operations on a memory, you can use globallock to lock the memory and obtain the pointer for direct operations.

 
"Handle" (handle), handle is intended to be the handle, the meaning of the handle. It is something you deal with the operating system. For example, if you have lost your mind (I am talking about it, for example, haha) and unfortunately let me catch the handle, then you have to do what I want you to do, it's because you have something on me. This is also true for programming. For example, if we want to manipulate a window, we must "grasp its handle". Only in this way can we change its attributes and style, or even destroy it ). Let's cite another example. For example, if you are admitted to a university, the school (operating system) will give you a student ID number after you enter the university. Note that this number is specified by the school and you cannot select it. With this number (student ID card, for example, a multi-purpose student ID card), you can enjoy the services provided by the school. For example, you can borrow books from the library, go to the canteen for dinner, and go to the classroom for classes. But you cannot buy beer in the canteen because the school does not allow this service. In computer systems, the service provided by the system is API calling. With handle, you can confidently propose the service to the system to call the API. The pointer has a lot of power. With the pointer, you can drink and fight everywhere, and the school (operating system) cannot handle it, the difference between a handle and a pointer is that a handle can only call the services provided by the system. While the handle is a number that can be differentiated from each other, it is different from the ordinary idnumber. The ordinary idnumber can be defined by the programmer, but the handle cannot, it is specified by the system when an object is generated to distinguish the objects in the system. This handle is not assigned by the programmer. In practical applications, file handles and window handles are commonly used. For example, the window handle value is a long integer, and each form is represented by a handle. Therefore, the handle will not be repeated. Many functions will use the form handle.

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.