Windows programming (i) understanding of handles

Source: Internet
Author: User

General overview Handle , which is the basis for the entire Windows programming. A handle is a unique integer value used, that is, a value of 4 bytes (8 bytes in a 64-bit program) to identify different objects in the application and different instances in the same object , such as a window, button, icon, scroll bar, output device, control, or file. The application is able to access the information of the corresponding object through a handle, but the handle is not a pointer to a large number of handles are used to identify many objects.

Origin

Windows has a handle, fundamentally rooted in the memory management mechanism of the problem-virtual address, in short, the data address needs to change, after the change will need someone to record management changes, (as if the hukou management), so the system with a handle to record data address changes.

The address is obtained when the data object is loaded into memory, but the address is not fixed. (As to why and under what circumstances the specific need to study the virtual address of the principle and mechanism I only mention here I am sure to know the example) the data object will move between the memory and the hard disk as needed (for example, infrequently used data will make up the memory space used for common data and be eliminated into the virtual memory in the hard disk to optimize the resources Improve efficiency performance), so its physical address is always changing, then as a manager must be the management of the changes occurred in the object of knowledge, so the system for the process to assign a fixed address (handle) to store the process of data object changes after the address is also the current address, in fact, the design mechanism is very simple : When a department of a system moves the address of an object, it is escalated to the department manager to which the handle belongs, and the manager writes the changes to the handle. When the data is re-employed, it is accessed by content within its owning handle.

Handle, English: HANDLE, is a very important concept in Windows programming and plays an important role in many places. But the resulting handle concept is similar, for example: Microsoft Windows 3 Developer ' s Workshop (Microsoft Press,by Richard Wilton) The concept of a handle in a book is: In a Windows environment, a handle is used to identify a project.

In programming, a handle is a special kind of smart pointer. A handle is used when an application is to reference a block or object of memory managed by another system, such as a database or operating system.

The difference between a handle and a normal pointer is that the pointer contains the memory address of the reference object, and the handle is a reference identity managed by the system that can be relocated to a memory address by the system. This pattern of indirect access to objects enhances the system's control over referenced objects.

In the memory management of the operating systems of the 80 's, such as Mac OS and Windows, handles were widely used. The file descriptor of a UNIX system is basically also a handle. Like other desktop environments, WINDOWSAPI uses a large number of handles to identify objects in the system and to establish communication channels between the operating system and user space. For example, a form on the desktop is identified by a handle to an HWND type. Today, the increase in memory capacity and the virtual memory algorithm make the simpler pointers more popular, while the kind of handles that point to another pointer are cold. Nonetheless, many operating systems still place pointers to private objects and the internal array of processes passed to the client is called a handle.

Origin

Origin

Origin

Origin

Origin

Origin

This article is from the "0 ℃ non-security" blog, so be sure to keep this source http://774733240.blog.51cto.com/10348799/1662931

Windows programming (i) understanding of handles

Related Article

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.