Handling Low-Memory Situations

< BACK  NEXT >
[oR]

Applications running under Windows CE should always be prepared for low- or out-of-memory situations. Requests to allocate memory may fail (in which case they return a NULL pointer). In Windows CE implementations with a shell (such as Pocket PC or Handheld PC), applications should respond to WM_ HIBERNATE messages.

Windows CE recognizes three distinct low-memory threshold situations, and these are activated by any application allocating new pages of memory. With Pocket PC three low-memory situations are recognized, and the following actions are taken by the operating system:

  • Hibernation. The shell sends a WM_HIBERNATE to the application that has been inactive the longest.

  • Low Memory. The shell sends a WM_CLOSE message to the application that has been inactive the longest. The shell continues to send WM_CLOSE messages to applications until the free memory climbs above the low-memory threshold, or when only the foreground application remains open.

  • Critical Memory. No new applications can be opened.

With Handheld PC applications are not automatically closed. Instead, an out-of-memory dialog box is displayed and the user is requested to close down applications.

The free memory values for these threshold situations depend on the platform (such as Pocket PC and Handheld PC) and the page size (either 1 KB or 4 KB). Table 12.1 shows the threshold values for Pocket PC and Handheld PC for devices with 1-KB page size. Platforms without a shell do not receive WM_HIBERNATE or WM_CLOSE messages.

Table 12.1. Low-memory threshold values
Threshold Pocket PC on Windows 3.0 Handheld PC on Windows 2.11
Hibernation threshold 128 KB 200 KB
Low-memory threshold 64 KB 128 KB
Critical memory threshold 16 KB 24 KB

Responding to a WM_CLOSE Message

A Windows CE application should be prepared to receive a WM_CLOSE message from the shell and not just from the application's own interface. In response to a WM_CLOSE message from the shell, the application should save any documents without prompting the user, and free any resources prior to closing.

Responding to a WM_HIBERNATE Message

When an application receives a WM_HIBERNATE message, it should free up as much memory as possible by doing the following:

  • De-allocating any memory structures that can be recreated

  • Closing any unnecessary windows

  • Deleting any fonts, menus, bitmaps, strings, or other resources

When the user or the operating system next activates the application, a WM_ACTIVATE message will be received by the application. At this point the application can reallocate memory or recreate windows as necessary.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net