OfferVirtualMemory function (memoryapi.h)

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.

The specified pages will be marked as inaccessible, removed from the process working set, and will not be written to the paging file.

To later reclaim offered pages, call ReclaimVirtualMemory.

Syntax

DWORD OfferVirtualMemory(
  [in] PVOID          VirtualAddress,
  [in] SIZE_T         Size,
  [in] OFFER_PRIORITY Priority
);

Parameters

[in] VirtualAddress

Page-aligned starting address of the memory to offer.

[in] Size

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

[in] Priority

Priority indicates how important the offered memory is to the application. A higher priority increases the probability that the offered memory can be reclaimed intact when calling ReclaimVirtualMemory. The system typically discards lower priority memory before discarding higher priority memory. Priority must be one of the following values.

Value Meaning
VMOfferPriorityVeryLow
0x00000001
The offered memory is very low priority, and should be the first discarded.
VMOfferPriorityLow
0x00000002
The offered memory is low priority.
VMOfferPriorityBelowNormal
0x00000003
The offered memory is below normal priority.
VMOfferPriorityNormal
0x00000004
The offered memory is of normal priority to the application, and should be the last discarded.

Return value

ERROR_SUCCESS if successful; a System Error Code otherwise.

Remarks

To reclaim offered pages, call ReclaimVirtualMemory. The data in reclaimed pages may have been discarded, in which case the contents of the memory region is undefined and must be rewritten by the application.

Do not call OfferVirtualMemory to offer virtual memory that is locked. Doing so will unlock the specified range of pages.

Note that offering and reclaiming virtual memory is similar to using the MEM_RESET and MEM_RESET_UNDO memory allocation flags, except that OfferVirtualMemory removes the memory from the process working set and restricts access to the offered pages until they are reclaimed.

Requirements

Requirement Value
Minimum supported client Windows 8.1 Update [desktop apps | UWP apps]
Minimum supported server Windows Server 2012 R2 Update [desktop apps | UWP apps]
Target Platform Windows
Header memoryapi.h (include Windows.h, Memoryapi.h)
Library onecore.lib
DLL Kernel32.dll

See also

DiscardVirtualMemory

Memory Management Functions

ReclaimVirtualMemory

Virtual Memory Functions

VirtualAlloc

VirtualFree

VirtualLock

VirtualQuery