Memory Management Functions

General memory functions

Function Description
AddSecureMemoryCacheCallback Registers a callback function to be called when a secured memory range is freed or its protections are changed.
CopyDeviceMemory Copies memory from one location to another without interference from compiler optimizations in situations where the developer needs to additionally be sure that alignment faults will not be generated when accessing device memory.
CopyMemory Copies a block of memory from one location to another.
CopyVolatileMemory Copies the contents of a source memory block to a destination memory block.
CreateMemoryResourceNotification Creates a memory resource notification object.
FillDeviceMemory Sets the contents of a buffer without interference from compiler optimizations in situations where the developer needs to additionally be sure that alignment faults will not be generated when accessing device memory.
FillMemory Fills a block of memory with a specified value.
FillVolatileMemory Fills a block of memory with the specified fill value.
GetLargePageMinimum Retrieves the minimum size of a large page.
GetPhysicallyInstalledSystemMemory Retrieves the amount of RAM that is physically installed on the computer.
GetSystemFileCacheSize Retrieves the current size limits for the working set of the system cache.
GetWriteWatch Retrieves the addresses of the pages that have been written to in a region of virtual memory.
GlobalMemoryStatusEx Obtains information about the system's current usage of both physical and virtual memory.
MoveMemory Moves a block of memory from one location to another.
MoveVolatileMemory Copies the contents of a source memory block to a destination memory block, and supports overlapping source and destination memory blocks.
QueryMemoryResourceNotification Retrieves the state of the specified memory resource object.
RemoveSecureMemoryCacheCallback Unregisters a callback function that was previously registered with the AddSecureMemoryCacheCallback function.
ResetWriteWatch Resets the write-tracking state for a region of virtual memory.
SecureMemoryCacheCallback An application-defined function that is called when a secured memory range is freed or its protections are changed.
SecureZeroMemory Fills a block of memory with zeros.
SecureZeroMemory2 Fills a block of memory with zeros in a way that is guaranteed to be secure.
SetSystemFileCacheSize Limits the size of the working set for the file system cache.
ZeroDeviceMemory Sets the contents of a buffer to zeros without interference from compiler optimizations in situations where the developer needs to additionally be sure that alignment faults will not be generated when accessing device memory.
ZeroMemory Fills a block of memory with zeros.
ZeroVolatileMemory Fills a block of memory with zeros.

Data execution prevention functions

These functions are used with Data Execution Prevention (DEP).

Function Description
GetProcessDEPPolicy Retrieves DEP settings for a process.
GetSystemDEPPolicy Retrieves DEP settings for the system.
SetProcessDEPPolicy Changes DEP settings for a process.

File mapping functions

These functions are used in file mapping.

Function Description
CreateFileMappingA Creates or opens a named or unnamed file-mapping object for a specified file.
CreateFileMappingW Creates or opens a named or unnamed file-mapping object for a specified file.
CreateFileMapping2 Creates or opens a named or unnamed file mapping object for a specified file. You can specify a preferred NUMA node for the physical memory as an extended parameter; see the ExtendedParameters parameter.
CreateFileMappingFromApp Creates or opens a named or unnamed file-mapping object for a specified file from a Windows Store app.
CreateFileMappingNuma Creates or opens a named or unnamed file-mapping object for a specified file, and specifies the NUMA node for the physical memory.
FlushViewOfFile Writes to the disk a byte range within a mapped view of a file.
GetMappedFileName Checks whether the specified address is within a memory-mapped file in the address space of the specified process. If so, the function returns the name of the memory-mapped file.
MapViewOfFile Maps a view of a file mapping into the address space of a calling process.
MapViewOfFile2 Maps a view of a file or a pagefile-backed section into the address space of the specified process.
MapViewOfFile3 Maps a view of a file or a pagefile-backed section into the address space of the specified process.
MapViewOfFile3FromApp Maps a view of a file mapping into the address space of a calling process from a Windows Store app.
MapViewOfFileEx Maps a view of a file mapping into the address space of a calling process. A caller can optionally specify a suggested memory address for the view.
MapViewOfFileExNuma Maps a view of a file mapping into the address space of a calling process, and specifies the NUMA node for the physical memory.
MapViewOfFileFromApp Maps a view of a file mapping into the address space of a calling process from a Windows Store app.
MapViewOfFileNuma2 Maps a view of a file or a pagefile-backed section into the address space of the specified process.
OpenFileMapping Opens a named file-mapping object.
OpenFileMappingFromApp Opens a named file-mapping object.
UnmapViewOfFile Unmaps a mapped view of a file from the calling process's address space.
UnmapViewOfFile2 Unmaps a previously mapped view of a file or a pagefile-backed section.
UnmapViewOfFileEx Unmaps a previously mapped view of a file or a pagefile-backed section.

AWE functions

These are the AWE functions.

Function Description
AllocateUserPhysicalPages Allocates physical memory pages to be mapped and unmapped within any AWE region of the process.
AllocateUserPhysicalPagesNuma Allocates physical memory pages to be mapped and unmapped within any AWE region of the process, and specifies the NUMA node for the physical memory.
FreeUserPhysicalPages Frees physical memory pages previously allocated with AllocateUserPhysicalPages.
MapUserPhysicalPages Maps previously allocated physical memory pages at the specified address within an AWE region.
MapUserPhysicalPagesScatter Maps previously allocated physical memory pages at the specified address within an AWE region.

Heap functions

These are the heap functions.

Function Description
GetProcessHeap Obtains a handle to the heap of the calling process.
GetProcessHeaps Obtains handles to all of the heaps that are valid for the calling process.
HeapAlloc Allocates a block of memory from a heap.
HeapCompact Coalesces adjacent free blocks of memory on a heap.
HeapCreate Creates a heap object.
HeapDestroy Destroys the specified heap object.
HeapFree Frees a memory block allocated from a heap.
HeapLock Attempts to acquire the lock associated with a specified heap.
HeapQueryInformation Retrieves information about the specified heap.
HeapReAlloc Reallocates a block of memory from a heap.
HeapSetInformation Sets heap information for the specified heap.
HeapSize Retrieves the size of a memory block allocated from a heap.
HeapUnlock Releases ownership of the lock associated with a specified heap.
HeapValidate Attempts to validate a specified heap.
HeapWalk Enumerates the memory blocks in a specified heap.

Virtual memory functions

These are the virtual memory functions.

Function Description
DiscardVirtualMemory Discards the memory contents of a range of memory pages, without decommitting the memory. The contents of discarded memory is undefined and must be rewritten by the application.
OfferVirtualMemory Indicates that the data contained in a range of memory pages is no longer needed by the application and can be discarded by the system if necessary.
PrefetchVirtualMemory Prefetches virtual address ranges into physical memory.
QueryVirtualMemoryInformation Returns information about a page or a set of pages within the virtual address space of the specified process.
ReclaimVirtualMemory Reclaims a range of memory pages that were offered to the system with OfferVirtualMemory.
SetProcessValidCallTargets Provides CFG with a list of valid indirect call targets and specifies whether they should be marked valid or not.
VirtualAlloc Reserves or commits a region of pages in the virtual address space of the calling process.
VirtualAlloc2 Reserves, commits, or changes the state of a region of memory within the virtual address space of a specified process. The function initializes the memory it allocates to zero.
VirtualAlloc2FromApp Reserves, commits, or changes the state of a region of pages in the virtual address space of the calling process. Memory allocated by this function is automatically initialized to zero.
VirtualAllocEx Reserves or commits a region of pages in the virtual address space of the specified process.
VirtualAllocExNuma Reserves or commits a region of memory within the virtual address space of the specified process, and specifies the NUMA node for the physical memory.
VirtualAllocFromApp Reserves, commits, or changes the state of a region of pages in the virtual address space of the calling process. Memory allocated by this function is automatically initialized to zero.
VirtualFree Releases or decommits a region of pages within the virtual address space of the calling process.
VirtualFreeEx Releases or decommits a region of memory within the virtual address space of a specified process.
VirtualLock Locks the specified region of the process's virtual address space into physical memory.
VirtualProtect Changes the access protection on a region of committed pages in the virtual address space of the calling process.
VirtualProtectEx Changes the access protection on a region of committed pages in the virtual address space of the calling process.
VirtualProtectFromApp Changes the protection on a region of committed pages in the virtual address space of the calling process.
VirtualQuery Provides information about a range of pages in the virtual address space of the calling process.
VirtualQueryEx Provides information about a range of pages in the virtual address space of the calling process.
VirtualUnlock Unlocks a specified range of pages in the virtual address space of a process.

Global and local functions

Also see global and local functions. These functions are provided for compatibility with 16-bit Windows and are used with Dynamic Data Exchange (DDE), the clipboard functions, and OLE data objects. Unless documentation specifically states that a global or local function should be used, new applications should use the corresponding heap function with the handle returned by GetProcessHeap. For equivalent functionality to the global or local function, set the heap function's dwFlags parameter to 0.

Function Description Corresponding heap function
GlobalAlloc, LocalAlloc Allocates the specified number of bytes from the heap. HeapAlloc
GlobalDiscard, LocalDiscard Discards the specified global memory block. Not applicable.
GlobalFlags, LocalFlags Returns information about the specified global memory object. Not applicable. Use HeapValidate to validate the heap.
GlobalFree, LocalFree Frees the specified global memory object. HeapFree
GlobalHandle, LocalHandle Retrieves the handle associated with the specified pointer to a global memory block. This function should be used only with OLE and clipboard functions that require it. Not applicable.
GlobalLock, LocalLock Locks a global memory object and returns a pointer to the first byte of the object's memory block. Not applicable.
GlobalReAlloc, LocalReAlloc Changes the size or attributes of a specified global memory object. HeapReAlloc
GlobalSize, LocalSize Retrieves the current size of the specified global memory object. HeapSize
GlobalUnlock, LocalUnlock Decrements the lock count associated with a memory object. This function should be used only with OLE and clipboard functions that require it. Not applicable.

Bad memory functions

Function Description
BadMemoryCallbackRoutine An application-defined function registered with the RegisterBadMemoryNotification function that is called when one or more bad memory pages are detected.
GetMemoryErrorHandlingCapabilities Gets the memory error handling capabilities of the system.
RegisterBadMemoryNotification Registers a bad memory notification that is called when one or more bad memory pages are detected.
UnregisterBadMemoryNotification Closes the specified bad memory notification handle.

Enclave functions

Function Description
CreateEnclave Creates a new uninitialized enclave. An enclave is an isolated region of code and data within the address space for an application. Only code that runs within the enclave can access data within the same enclave.
InitializeEnclave Initializes an enclave that you created and loaded with data.
IsEnclaveTypeSupported Retrieves whether the specified type of enclave is supported.
LoadEnclaveData Loads data into an uninitialized enclave that you created by calling CreateEnclave.

ATL thunk functions

Function Description
AtlThunk_AllocateData Allocates space in memory for an ATL thunk.
AtlThunk_DataToCode Returns an executable function corresponding to the AtlThunkData_t parameter.
AtlThunk_FreeData Frees memory associated with an ATL thunk.
AtlThunk_InitData Initializes an ATL thunk.

Obsolete Functions

These functions are provided only for compatibility with 16-bit versions of Windows:

The function below can return incorrect information, and should not be used. Instead, use the GlobalMemoryStatusEx function.