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:
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.
Responding to a WM_CLOSE MessageA 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 MessageWhen an application receives a WM_HIBERNATE message, it should free up as much memory as possible by doing the following:
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.
|