RegisterOOMNotification (Compact 2013)
3/28/2014
This function is used to enable event handles to receive out-of-memory (OOM) notifications.
Syntax
BOOL RegisterOOMNotification (
PHANDLE phMemLow,
PHANDLE phMemPressure,
PHANDLE phMemHealthy
);
Parameters
- phMemLow
[in] Pointer to a handle to receive the event handle of the manual-reset event that will be signaled when memory is low.
- phMemPressure
[in] Pointer to a handle to receive the event handle of the manual-reset event that will be signaled when memory is under pressure.
- phMemHealthy
[in] Pointer to a handle to receive the event handle of the manual-reset event that will be signaled when memory is in a healthy state, which is above the healthy threshold.
Return Value
Returns a nonzero value if successful; otherwise, fails.
Remarks
The caller is responsible for closing the handles. All of the handles returned are wait-only handles where the caller can only call WaitForSingleObject or WaitForMultipleObjects on these handles.
Example
The following example code illustrates how to use this function in a custom OOM handler.
HANDLE hMemLow, hMemPressure, hMemHealthy;
// get OOM notification event
if (RegisterOOMNotification (&hMemLow, &hMemPressure, &hMemHealthy) {
HANDLE hEvts[2] = { hMemLow, hMemPressure};
while (g_bHandleOOM) {
// wait for OOM notifications
DWORD dwWaitResult = WaitForMultipleObjects (2, hEvts, FALSE, INFINITE);
// try to free memory based on the OOM event, until
// memory is healthy again.
do {
// try to free memory, typically done by closing applications
// depending on the wait result.
if (!TryToFreeMemory (dwWaitResult)) {
// can’t free more memory. Block and hope for someone
// else to release memory. Or you can choose to reboot
// the device here as memory is low and couldn't recover.
WaitForSingleObject (hMemHealthy, INFINITE);
}
} while (WaitForSingleObject (hMemHealthy, 0) != WAIT_OBJECT_0);
}
CloseHandle (hMemLow);
CloseHandle (hMemPressure);
CloseHandle (hMemHealthy);
}
Requirements
Header |
pkfuncs.h |