Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DiscardVirtualMemory function

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.

Syntax


DWORD WINAPI DiscardVirtualMemory(
  _In_ PVOID  VirtualAddress,
  _In_ SIZE_T Size
);

Parameters

VirtualAddress [in]

Page-aligned starting address of the memory to discard.

Size [in]

Size, in bytes, of the memory region to discard. Size must be an integer multiple of the system page size.

Return value

ERROR_SUCCESS if successful; a System Error Code otherwise.

Remarks

If DiscardVirtualMemory fails, the contents of the region is not altered.

Use this function to discard memory contents that are no longer needed, while keeping the memory region itself committed. Discarding memory may give physical RAM back to the system. When the region of memory is again accessed by the application, the backing RAM is restored, and the contents of the memory is undefined.

Important  Calls to DiscardVirtualMemory will fail if the memory protection is not PAGE_READWRITE.
 

Requirements

Minimum supported client

Windows 8.1 Update [desktop apps | UWP apps]

Minimum supported server

Windows Server 2012 R2 Update [desktop apps | UWP apps]

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Memory Management Functions
Virtual Memory Functions
OfferVirtualMemory
ReclaimVirtualMemory
VirtualAlloc
VirtualFree
VirtualLock
VirtualQuery

 

 

Show: