"Handle" is used to operate an "object/resource, that is: operating a certain target", so what exactly does "handle" mean? How to explain the release of a handle?
"Handle" is used to operate an "object/resource, that is: operating a certain target", so what exactly does "handle" mean? How to explain the release of a handle?
The object is like your object, and the handle is like your object's mobile phone number. You don't have to worry about where your object is and what it is doing all the time. You can find it by just calling it when you need it. You can even call it when releasing it. Said: We broke up.
The English word for
handle
is handle
.
Handle is the callback function.
Handle
(handle) can be understood semantically as handle
. Use this handle to get resources. Pulling the handle is equivalent to holding resources, and operating on the handle is equivalent to operating resources by following the clues. For example:
<code class="php">// 建立资源 $ch = curl_init(); // 根据句柄操作资源 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // 根据句柄执行这个资源 $head = curl_exec($ch); </code>
There is also a word in English calledlove handle
It refers to the small fat around the belly that can be pinched and pinched. The literal translation can be understood as "love handle"
Similar to a channel, an object that maintains a certain state.
Some resources cannot be directly operated due to their nature, so they need to be operated through handles.
For example:
Operation of the database requires identity, so the handle after logging in to the database carries the identity information to operate the database
The reading and writing of files has the file pointer position. Reading and writing need to control the pointer position. The handle provides a stateful channel.
The timer is a state. The timing state is assigned to the handle. When something is triggered, the handle can be processed (cancel the timer, trigger in advance), etc.
Your application often needs to perform some operations on objects (data files, custom data structures, etc.), and the handle can be simply understood as a pointer to these objects. After your program starts, these objects are in memory are not static. On the one hand, due to processor scheduling and other reasons, on the other hand, most current operating systems are based on virtual memory space. In this case, the memory manager will often move objects back and forth to meet the current running requirements. Yes, if we only rely on a pointer to find objects - pointing to a fixed memory address, then there is obviously no way to deal with the changing actual memory. Therefore, the handle can be said to be a pointer to a pointer. , although it itself does not directly point to the object, you can use it to learn about the changes in the object in memory, and then obtain the object indirectly
In other words, the address of the actual object in the memory is usually not fixed, and the fixed handle describes the location of the corresponding object in the memory
In C language, there are pointers to structures