最近一直在从事Windows Mobile Shell的工作,其中就会考虑在低内存下运行的情况,在wmshell 和 windowsmobile Blog 里都发现了这篇文章 《 HOW THE WINDOWS MOBILE 5.0 SHELL HANDLES LOW MEMORY SITUATIONS 》,提供了很好的系统级处理方式。
文章对在Hibernate, Kernel-Check, Critical, Execute, Kernel-Critical下的各种模式做了阐述,并提供了一小端代码,可以参考,如下。详细参见原文。
#define MIN_MEMORY_TO_RUN 2*1024*1024
MEMORYSTATUS mst;
mst.dwLength= sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&mst);
If (mst.dwAvailPhys < MIN_MEMORY_TO_RUN)
{
// Try to free memory by asking Shell to shutdown apps
if (!SHCloseApps(MIN_MEMORY_TO_RUN))
{
// Handle the case where memory could not be freed
...
MEMORYSTATUS mst;
mst.dwLength= sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&mst);
If (mst.dwAvailPhys < MIN_MEMORY_TO_RUN)
{
// Try to free memory by asking Shell to shutdown apps
if (!SHCloseApps(MIN_MEMORY_TO_RUN))
{
// Handle the case where memory could not be freed
...