[Reprint] handle and pointer

Source: Internet
Author: User
A handle is a pointer to some table indexes. Both the handle and pointer are addresses. A handle is a key concept in Windows programming. ProgramAlways deal with various handles.

A handle is a unique number used to identify many different object types, such as Windows, menus, memory, brushes, and paint brushes. In Win32, the handle is a pointer to a "untyped object" (void *), that is, a 4-byte long data.
No matter what its nature is, the handle is not a real pointer. In terms of structure, a handle is a pointer, although it does not point to the memory location used to store an object. In fact, the handle points to a location that contains a reference to this object.
The handle declaration is as follows:
Typedef
Void * handle

Because Windows is a multitasking operating system, it can run multiple programs or multiple copies of one program at a time. These running programs are called an instance. To manage multiple copies of the same program, Windows introduces an instance handle. Windows creates a table for each application, and the instance handle is like an index for this table.

The difference is:
1. The handle refers to a very complex structure and can be related to the system. For example, the thread handle mentioned above points to a class or structure, it is closely related to the system. When a thread is terminated due to unpredictable reasons, the system can return the information it occupies, such as CPU and memory, in turn, I want to know that some items in the handle interact with the system. Because Windows is a multi-task system, it may need to allocate memory, recycle memory, and reorganize the memory at any time.

2. the pointer can also point to a complex structure, but it is usually user-defined, so the necessary work must be completed by the user, especially when deleting.
However, there are also some pointers in VC ++ 6.0, which are used only when dealing with small issues, such as the most common character pointers, it also needs to be processed by the user. If you dynamically allocate memory, but cstring does not need to be processed by the user, it is actually a class in VC ++, so the operations are completed by the member function, the constructor generates (allocates) and deletes (recycles) the constructor.

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.