Essence of the handle

xiaoxiao2021-03-18  222

The so-called handle is actually a data, a LONG (long-term) data

The handle is Wondows to identify unique integers of objects established or used by the application, Windows uses a wide variety of handle identifies such as application instances, windows, control, bitmaps, GDI objects, and more. The Windows handle is a bit icon in a C language.

From the above definition we can see, the handle is an identifier, which is to identify objects or projects. It is like our name, everyone will have one, the names of different people are different, but, There may also have a name and the same person. From the data type, it is just a 16-bit unsigned integer. Applications almost always get a handle by calling a Windows function, then other Windows functions can use the handle to reference the corresponding object.

If you want to know your handle, I can tell you that the handle is a pointer to the pointer. We know that the so-called pointer is a memory address. After the application starts, the objects that make up this program are residing in memory. If you simply understand, it seems that we can use this address to access the object at any time as you know the first address of this memory. However, if you really think, then you have a big mistake. We know that Windows is an operating system based on virtual memory. In this system environment, Windows Memory Manager often comes back and forth in memory, which meets the memory needs of various applications. Objects are moved means that its address changes. If the address is always so changed, where do we go to the object?

In order to solve this problem, the Windows operating system makes some internal storage addresses for each application, which is used to register the address changes in the memory, and this address (position of the storage unit) is constant. The Windows Memory Manager informs the object's new address to save the object after moving the object in the memory. This way we only need to remember this handle address, you can indirectly know which location in the memory is specifically in memory. This address is assigned by the system when the object is loaded (LOAD), and when the system is uninstalled (unload) is released to the system.

Handle Address (Stable) → Repends on the address in memory - ─ → Object in memory (unstable) → actual object

Essential: The Windows program is not used by physical address to identify a memory block, file, task, or dynamic load module. Conversely, the Windows API assigns a determined handle to these items and returns the handle to the application, then pass the handle. To operate.

However, it must be noted that the program is restarted each time, the system cannot guarantee the handle allocated to this program or the original handle, and most of the cases are different. If we see movies to see movies into the startup operation of an application, the handle to allocate the application is always different, this is always the same as the tickets sold by each cinema. .

转载请注明原文地址:https://www.9cbs.com/read-129927.html

New Post(0)