INFO: Out of Memory Handler Must Be Initialized If GWES "OOM" Component Is Removed (244352)



The information in this article applies to:

  • Microsoft Windows CE Embedded Toolkit for Visual C++ 5.0
  • Microsoft Windows CE Platform Builder 2.11
  • Microsoft Windows CE Platform Builder 2.12
  • Microsoft Windows CE 2.10 Enhancement Pack for Windows CE Embedded Toolkit for Visual C++ 5.0

This article was previously published under Q244352

SUMMARY

The Graphics, Windowing, and Event Subsystem (GWES) of Windows CE initializes and responds to the out of memory (OOM) condition that is signaled by the kernel. If the OOM component of GWES is removed by the original equipment manufacturer (OEM), then the OEM must initialize the out of memory handler by calling the SetGwesOOMEvent function and optionally creating a event handler for OOM events.

MORE INFORMATION

If an OEM does not include the OOM component, then the OEM must call the SetGwesOOMEvent function in order to enable control of the following:
  • Page-out code: When memory is low, the kernel will page-out or discard code that is marked as discardable. This enables memory to be freed for use by other processes.
  • Reclaim unused stack space: When memory is low, the kernel will attempt to reclaim memory that is used by a thread's stack, which is no longer needed by the thread.
The SetGwesOOMEvent function enables the enhanced memory management features of Windows CE:
void SetGwesOOMEvent (	
	HANDLE hEvent,	
	DWORD cpLow,	
	DWORD cpCritical,	
	DWORD cpLowBlockSize,	
	DWORD cpCriticalBlockSize	
);
				

Parameters

hEventA handle to the event that the kernel sets when memory has become low or critically low.
cpLowThe number of free memory pages that will trigger a low memory condition. When memory goes below this level, hEvent is set.
cpCriticalThe number of free memory pages that will trigger a critically low memory condition. When memory goes below this level, hEvent is set.
cpLowBlockSizeThis is the size of the largest block that the kernel will allow to be allocated with VirtualAlloc when the allocation would leave the system with fewer than cpLow pages.
cpCriticalBlockSizeThis is the size of the largest block that the kernel will allow to be allocated with VirtualAlloc when the allocation would leave the system with fewer than cpCritical pages.


When the OOM component is included in GWES, SetGwesOOMEvent is called with the following default values, or values retrieved from the registry:
cpLow  = 30
cpCritical = 15
cpLowBlockSize  = 0x4000
cpCriticalBlockSize  = 2
				
When the OOM component is not present, and if SetGwesOOMEvent is not called, the kernel uses the default value of 0 (zero) for all parameters. In this case, the kernel will not attempt to page-out code until memory reaches zero and will not reclaim unused stack memory. Memory will still be reclaimed when threads, processes, memory allocations, and kernel objects are deleted.

In the absence of the GWES OOM component, an application that needs to monitor the memory state will pass in the parameters and then wait (by using WaitForSingleObject) on the event to be triggered by the kernel. When the kernel sets the event, the monitoring application queries the memory state to determine if memory was low or critical, and then takes the appropriate action. To query the current memory state, use the GlobalMemoryStatus function.

Modification Type:MajorLast Reviewed:4/15/2004
Keywords:kbinfo KB244352