GlobalLock的MSDN译文

来源:互联网 发布:java什么是过滤器 编辑:程序博客网 时间:2024/04/27 20:27
 
The GlobalLock function locks a global memory object and returns a pointer to the first byte of the object's memory block.
This function is provided only for compatibility with 16-bit versions of Windows.
锁定全局内存对象,并返回内存块的第一个字节的指针。
这个函数是为了保持和16Windows版本兼容而给出的。
 
LPVOID GlobalLock(
 HGLOBAL hMem   // handle to the global memory object
);
 
Handle to the global memory object. This handle is returned by either the GlobalAlloc or GlobalReAlloc function.
输入参数是一个全局内存对象,这个句柄对象是通过函数GlobalAlloc或者GlobalReAlloc得到的。
If the function succeeds, the return value is a pointer to the first byte of the memory block.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
如果函数调用成功了,则返回值是内存块的首字节的指针,如果失败了,则就返回NULL,可以利用函数GetLastError获得更多的失败信息。
 
The internal data structures for each memory object include a lock count that is initially zero. For movable memory objects, GlobalLock increments the count by one, and the GlobalUnlock function decrements the count by one. For each call that a process makes to GlobalLock for an object, it must eventually call GlobalUnlock. Locked memory will not be moved or discarded, unless the memory object is reallocated by using the GlobalReAlloc function. The memory block of a locked memory object remains locked until its lock count is decremented to zero, at which time it can be moved or discarded.
 
每一个内存块的内在结构中包含一个初始值为零的锁定计数器。
对于可以移动的内存对象而言,每调用GlobalLock一次,则锁定计数器会增加1,没调用GlobalUnlock一次,则会自动减1
只有两种情况可以移动或者清除内存:1、调用GlobalReAlloc函数;2、锁定计数器的值为0
 
Memory objects allocated with the GMEM_FIXED flag always have a lock count of zero. For these objects, the value of the returned pointer is equal to the value of the specified handle.
If the specified memory block has been discarded or if the memory block has a zero-byte size, this function returns NULL.
含有标志GMEM_FIXED的内存对象的锁定计数器的值始终为零。这些内存对象在调用这个函数后的指针值和对应的句柄值是一致的。
Discarded objects always have a lock count of zero.
被清除的对象的锁定计数器的值始终为零。
 
原创粉丝点击