HeapFree

HeapFree

释放由HeapAlloc HeapReAlloc 函数从堆分配的内存块。

BOOL HeapFree(

  HANDLE hHeap,

  DWORD dwFlags,

  LPVOID lpMem

);

Parameters

hHeap

[in] 将要被释放的内存块的堆的句柄。该句柄由HeapCreate GetProcessHeap函数返回。

dwFlags

[in] 堆释放选项。当使用HeapCreate函数创建堆时,选用以下值来覆盖相应的在flOptions中指定的值。

Value

Meaning

HEAP_NO_SERIALIZE
0x00000001

序列化访问时将不会被使用更多的信息参看 Remarks

为了确保对于这个函数所有调用的序列化访问不可用, HeapCreate的调用中指定 HEAP_NO_SERIALIZE。 在这种情况下,不需要在这个函数额外的指定 HEAP_NO_SERIALIZE。

当访问进程堆时,不要指定这个值。系统会在应用程序的进程中创建额外的线程,例如一个CTRL+C句柄,同时的访问这个进程堆。

lpMem

[in] 指向将要释放的内存块的指针。该指针由HeapAlloc HeapReAlloc返回

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. An application can call GetLastError for extended error information.

Remarks

You should not refer in any way to memory that has been freed by HeapFree. After that memory is freed, any information that may have been in it is gone forever. If you require information, do not free memory containing the information. Function calls that return information about memory (such as HeapSize) may not be used with freed memory, as they may return bogus data. Calling HeapFree twice with the same pointer can cause heap corruption, resulting in subsequent calls to HeapAlloc returning the same pointer twice.

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.

Example Code

For an example, see AWE Example.

Requirements

Client

Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.

Server

Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.

Header

Declared in Winbase.h; include Windows.h.

Library

Link to Kernel32.lib.

DLL

Requires Kernel32.dll.

See Also

Heap Functions, Memory Management Functions, GetProcessHeap, HeapAlloc, HeapCreate, HeapDestroy, HeapReAlloc, HeapSize, SetLastError

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值