Recently, I have a new understanding of the handle, so that I can learn it later.
Some time ago I wrote in my blog what is a handle (see what is a handle) but it does not explain why the handle should be introduced in the window system, as most people know, the handle is used in the window operating system to identify a resource. Obtaining the handle is the address of the resource. In this sentence, we can know two knowledge points:
1. The handle is unique to the Windows operating system. It is not used in Linux.
2. A handle is used to identify a resource and obtain the resource address.
Now, I want to ask a question? Since C ++ has pointers, why should I use a handle? Can't the pointer Save the resource address?
I will explain this question now.
Anyone who has learned operating system principles knows that an applicationProgramNot allCodeThey are all put into the memory. Even if they are put into the memory, it is impossible to stay in the memory throughout the runtime. After all, the memory is still a precious resource. Therefore, for a certain resource, the physical address may be different at different times, but in the kernel object table, the handle is actually an index. Based on this index, we can quickly find the physical address of the resource at this time. The handle is relatively stable, so the window operating system introduces the handle concept.