Memoryallocation function/memory management API
Reference :
Windows MSDN
Http://msdn.microsoft.com/en-us/library/aa908768.aspx
Supporting Information :
http://blog.csdn.net/susubuhui/article/details/7315094
Http://wenku.baidu.com/link?url=yxgCWePPV1kFaIUciEspYgm34wNAnMLDoduBlfsEEo-mW0JFRVEOkixomUjPatqw_ Joxzcqq1cloebszqluse1kiyhd6ysztmizly_spgps
http://blog.csdn.net/sharecode/article/details/7464915
For Windows , some API interfaces are provided for Heap Memory Management, independent of the c++/c program and only for Windows Platform API.
It is probably divided into the following groups of interfaces :
Old Heap interface globalxxx( new programs are not recommended, these functions exist primarily compatible with previously written programs ):
Globalalloc/globalrelloc/globalfree: Request a piece of memory from the Heap
Globallock/globalunlock: request a memory from GlobalAlloc 's memory
function Parameters :
The new Heap interface heapxxx:
heapcreate/heapdestroy/getprocessheap: Request a piece of memory from the Heap
heapalloc/heaprelloc/heapfree/heapsize: request a memory from HeapCreate 's memory
heapvalidatee: querying the Heap or Alloc information
Current process Heap Memory Interface localxxx:
localalloc/localrealloc/localfree/localsize: Request a memory from the memory of the current Heap , equivalent to from HeapAlloc GetProcessHeap memory in the application.
Virtual Address Memory Interface : Virtualxxx
virtualalloc/virtualfree/virtualprotect/virtualquery: request page memory data from the process heap. Usually used to apply for a large amount of memory, at least one page. reserves or commits a region of pages .
For more on this piece please refer to :http://blog.csdn.net/sharecode/article/details/7464915
Malloc,new,virtualalloc,heapalloc The execution efficiency of these groups :
Reference :http://blog.csdn.net/susubuhui/article/details/7315094
When allocating large memory, VirtualAlloc can show the advantage, and it is relatively slow to apply for small memory.
As for the small block of memory that is HeapAlloc > malloc > New, because it is called HeapAlloc, the direct use of HeapAlloc is much faster.
Expanded new interface Xxxex ( not all versions supported )
Ending with an Ex , such as Vitualallocex, can specify process handleto request a piece of memory from other running process spaces.
Function Description :
HeapCreate:
Request a piece of memory from the memory area as a heap. This function reserves memory in the shared memory area.
HeapDestroy:
Delete the heap created by HeapCreate . This function destroys the specified heap object.
GetProcessHeap:
Gets the heap Handleof the current process. Note This cannot be deleted using Destroy . This function obtains a handle to the heap of the calling process. This handle can then is used in callsto the HeapAlloc,heaprealloc, HeapFree, andheapsize functions.
HeapAlloc:
Requests a section of memory from the specified heap, which is not moved. This function allocates a block of memory from a heap. The allocated memory is not movable.
HeapReAlloc:
Re-request a piece of memory from the specified heap. This function reallocates a block of memory from a heap. The allocated memory is not movable.
HeapFree:
Release the memory requested by HeapAlloc or heaprealloc . This function frees a memory block from a heap. The memory block is allocated by the heapalloc ortheheaprealloc function.
HeapSize:
Query the size of a heapalloc memory based on Handle, memory start address. This function returns the size, in bytes, of a memory block allocated from a heap by the HeapAlloc or HeapReAlloc function.
HeapValidate:
Check that the memory requested under heap Handle or heap Handle is valid.
This function validates the specified heap. HeapValidate scans all the memory blocks in the heap and verifies, the heap control structures maintained by the heap Manager is in a consistent state. The HeapValidate function can also is used to validate a single memory block within a specified heap without checking the Validity of the entire heap.
Localalloc/localrealloc/localfree/localsize:
Operation from the current process Heap . This set of functions is equivalent to heapxxx specifying the Heap Handle as the current process Handle. Function Reference heapalloc/heaprealloc/heapfree/heapsize effect.
Localalloc:this function allocates the specified number of bytes from the heap.
in the linear Windows Embedded CE API Environment, there is no difference between the local heap and the global heap.< /c0>LocalAlloc is equivalent to heapalloc(GetProcessHeap, ...).
Virtualalloc/virtualfree/virtualprotect/virtualquery:
Request page space data from the current process space and apply a minimum of one page.
The VirtualAlloc function reserves or commits a region of pages in the virtual address space of the calling process. Memory allocated by this function is automatically initialized to zero and unless Mem_reset is specified.
to allocate memory in the address space of another process, use the VirtualAllocEx function.
Win memory allocation function (GLOBALALLOC/HEAPALLOC/LOCALALLOC/VIRTUALALLOC)