Kernel32VirtualFreeEx(IntPtr, IntPtr, IntPtr, MemoryFreeType) Method

Releases, decommits, or releases and decommits a region of memory within the virtual address space of a specified process.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", SetLastError = true)]
public static bool VirtualFreeEx(
	IntPtr process,
	IntPtr address,
	IntPtr size,
	MemoryFreeType freeType
)

Parameters

process  IntPtr
A handle to a process. The function frees memory within the virtual address space of the process.

The handle must have the VirtualMemoryOperation access right.

address  IntPtr
A pointer to the starting address of the region of memory to be freed.

If the freeType parameter is Release, this parameter must be the base address returned by the VirtualAllocEx(IntPtr, IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions) function when the region of pages is reserved.

size  IntPtr
The size of the region of memory to be freed, in bytes.

If the freeType parameter is Release, this parameter must be 0 (zero).

The function frees the entire region that is reserved in the initial allocation call to VirtualAlloc(IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions) function.

If freeType parameter is Decommit, the function decommits all memory pages that contain one or more bytes in the range from the address parameter to (address+size). This means, for example, that a 2-byte region of memory that straddles a page boundary causes both pages to be decommitted.

If address parameter is the base address returned by VirtualAllocEx(IntPtr, IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions) and size parameter is 0 (zero), the function decommits the entire region that is allocated by VirtualAllocEx(IntPtr, IntPtr, IntPtr, MemoryAllocationType, MemoryProtectionOptions). After that, the entire region is in the reserved state.

freeType  MemoryFreeType
The type of free operation.

Return Value

Boolean
If the function succeeds, the return value is .

If the function fails, the return value is .

To get extended error information, call GetLastWin32Error.

Remarks

See Also