网站首页  词典首页

请输入您要查询的函数:

 

术语 heapalloc
释义 HeapAlloc
语法:
C++
LPVOID WINAPI HeapAlloc(
__in HANDLE hHeap,
__in DWORD dwFlags,
__in SIZE_T dwBytes
);
HeapAlloc函数
块分配一个从堆中的内存。分配的内存不是移动。
参数
hHeap [in]
一个句柄,从该内存将被分配的堆。这种处理是由HeapCreate或GetProcessHeap函数返回。
dwFlags [in]
堆分配方案。指定这些值将覆盖指定相应的值时,堆与HeapCreate创建的任何。此参数可以是一个或多个下列值。
ValueMeaning
HEAP_GENERATE_EXCEPTIONS
0x00000004The系统将引发异常,以指示如外的内存不足的情况,而不是返回NULL,功能衰竭。
为确保例外生成所有这函数调用,指定在调用HEAP_GENERATE_EXCEPTIONS的HeapCreate。在这种情况下,没有必要的补充规定,在此函数调用HEAP_GENERATE_EXCEPTIONS。
HEAP_NO_SERIALIZE
0x00000001Serialized访问将不会被用于这种分配。有关更多信息,请参见备注。
为了确保序列化的访问被禁用所有这个函数调用,指定在调用HEAP_NO_SERIALIZE的HeapCreate。在这种情况下,没有必要的补充规定,在此函数调用HEAP_NO_SERIALIZE。
此值不应访问时指定进程的默认堆。该系统可在应用中创建的过程中,如按Ctrl + C处理,能够同时访问该进程的默认堆额外的线程。
HEAP_ZERO_MEMORY
0x00000008The分配的内存将被初始化为零。否则,内存未初始化为零。
dwBytes [in]
的字节数分配。
如果堆的hHeap参数指定为“非可增长的”堆,dwBytes必须小于0x7FFF8。您通过电话与一个非零值HeapCreate函数非可增长堆。
返回值
如果函数成功,返回值是对分配的内存块的指针。
如果函数失败,并且没有指定HEAP_GENERATE_EXCEPTIONS,返回值为NULL。
如果函数失败,并且您已指定HEAP_GENERATE_EXCEPTIONS,该函数可能会产生下列例外。特定的异常取决于堆腐败性质。
返回codeDescription
STATUS_NO_MEMORYThe分配尝试失败,因为一个可用内存堆损坏或缺少。
STATUS_ACCESS_VIOLATIONThe分配尝试失败,因为堆损坏或不当函数参数。
如果函数失败,它不会调用SetLastError。应用程序不能要求扩展的错误信息GetLastError函数。
备注
最少的内存量,如果HeapAlloc函数成功,它分配的要求。
分配从进程的默认堆,使用HeapAlloc与处理由GetProcessHeap函数返回的内存。
释放一个由HeapAlloc分配的内存块,使用HeapFree功能。
由HeapAlloc分配的内存没有移动。由HeapAlloc返回的地址是有效的,直到内存块被释放或重新分配,该内存块并不需要被锁定。由于系统无法压缩的私有堆,它可以变成碎片。
应用程序分配不同的分配大小大的内存量可以使用低碎片堆,以减少堆碎片。
序列化,确保相互排斥的两个或多个线程试图同时分配或来自同一堆空闲块。有一个小的性能成本的序列化,但必须使用多线程分配时,从同一个堆的可用内存。设置HEAP_NO_SERIALIZE价值消除了堆相互排斥。没有系列化,两个或多个线程使用同一个堆句柄可能试图分配或释放内存同时,在堆可能滋生腐败。该HEAP_NO_SERIALIZE值,因此,可以放心使用只有在下列情况下:
这个过程只有一个线程。
这一进程的多个线程,但只有一个线程调用特定堆的堆函数。
这一进程的多个线程,并且应用程序提供了相互排斥的机制,以一个特定的堆。
实例
有关示例,请参阅awe例子。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
堆函数
HeapFree
HeapReAlloc
内存管理功能
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==HeapAlloc Function
Allocates a block of memory from a heap. The allocated memory is not movable.
Syntax
C++
LPVOID WINAPI HeapAlloc(
__in HANDLE hHeap,
__in DWORD dwFlags,
__in SIZE_T dwBytes
);
Parameters
hHeap [in]
A handle to the heap from which the memory will be allocated. This handle is returned by the HeapCreate or GetProcessHeap function.
dwFlags [in]
The heap allocation options. Specifying any of these values will override the corresponding value specified when the heap was created with HeapCreate. This parameter can be one or more of the following values.
ValueMeaning
HEAP_GENERATE_EXCEPTIONS
0x00000004The system will raise an exception to indicate a function failure, such as an out-of-memory condition, instead of returning NULL.
To ensure that exceptions are generated for all calls to this function, specify HEAP_GENERATE_EXCEPTIONS in the call to HeapCreate. In this case, it is not necessary to additionally specify HEAP_GENERATE_EXCEPTIONS in this function call.
HEAP_NO_SERIALIZE
0x00000001Serialized access will not be used for this allocation. For more information, see Remarks.
To ensure that serialized access is disabled for all calls to this function, specify HEAP_NO_SERIALIZE in the call to HeapCreate. In this case, it is not necessary to additionally specify HEAP_NO_SERIALIZE in this function call.
This value should not be specified when accessing the process's default heap. The system may create additional threads within the application's process, such as a CTRL+C handler, that simultaneously access the process's default heap.
HEAP_ZERO_MEMORY
0x00000008The allocated memory will be initialized to zero. Otherwise, the memory is not initialized to zero.

dwBytes [in]
The number of bytes to be allocated.
If the heap specified by the hHeap parameter is a "non-growable" heap, dwBytes must be less than 0x7FFF8. You create a non-growable heap by calling the HeapCreate function with a nonzero value.
Return Value
If the function succeeds, the return value is a pointer to the allocated memory block.
If the function fails and you have not specified HEAP_GENERATE_EXCEPTIONS, the return value is NULL.
If the function fails and you have specified HEAP_GENERATE_EXCEPTIONS, the function may generate either of the following exceptions. The particular exception depends upon the nature of the heap corruption.
Return codeDescription
STATUS_NO_MEMORYThe allocation attempt failed because of a lack of available memory or heap corruption.
STATUS_ACCESS_VIOLATIONThe allocation attempt failed because of heap corruption or improper function parameters.

If the function fails, it does not call SetLastError . An application cannot call GetLastError for extended error information.
Remarks
If the HeapAlloc function succeeds, it allocates at least the amount of memory requested.
To allocate memory from the process's default heap, use HeapAlloc with the handle returned by the GetProcessHeap function.
To free a block of memory allocated by HeapAlloc, use the HeapFree function.
Memory allocated by HeapAlloc is not movable. The address returned by HeapAlloc is valid until the memory block is freed or reallocated; the memory block does not need to be locked. Because the system cannot compact a private heap, it can become fragmented.
Applications that allocate large amounts of memory in various allocation sizes can use the low-fragmentation heap to reduce heap fragmentation.
Serialization ensures mutual exclusion when two or more threads attempt to simultaneously allocate or free blocks from the same heap. There is a small performance cost to serialization, but it must be used whenever multiple threads allocate and free memory from the same heap. Setting the HEAP_NO_SERIALIZE value eliminates mutual exclusion on the heap. Without serialization, two or more threads that use the same heap handle might attempt to allocate or free memory simultaneously, likely causing corruption in the heap. The HEAP_NO_SERIALIZE value can, therefore, be safely used only in the following situations:
The process has only one thread.
The process has multiple threads, but only one thread calls the heap functions for a specific heap.
The process has multiple threads, and the application provides its own mechanism for mutual exclusion to a specific heap.
Examples
For an example, see AWE Example .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
Heap Functions
HeapFree
HeapReAlloc
Memory Management Functions
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa366597(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:22:12