How to: Determine Available Memory

You can use the Windows CE GlobalMemoryStatus function to get information about the amount of available program or storage memory on the device, as shown in the following code example.

Note   Because Windows Mobile-based devices dynamically adjust the relative amount of storage and program memory depending on the current needs of the user, your applications cannot programmatically force changes in the amount of memory allocated to running applications or data storage.

    MEMORYSTATUS   memInfo;
    STORE_INFORMATION   si;
    TCHAR   szBuf[MAX_PATH];

    // Program memory.
    memInfo.dwLength = sizeof(memInfo);
    GlobalMemoryStatus(&memInfo);

    wsprintf(szBuf, __TEXT("Total RAM: %d bytes\n Free: %d \nUsed: %d"), 
        memInfo.dwTotalPhys, memInfo.dwAvailPhys, memInfo.dwTotalPhys — 
        memInfo.dwAvailPhys);
    MessageBox(hwnd, szBuf, __TEXT("Program Memory"), MB_OK);

    // Storage memory.
    GetStoreInformation(&si);
  
    // dwStoreSize isn't exact due to compression. 
    wsprintf(szBuf, __TEXT("Free: %d"), si.dwFreeSize);
    MessageBox(hwnd, szBuf, __TEXT("Storage Memory"), MB_OK);

See Also

Application Hibernation

Handling Low Memory States

How to: Determine Battery Status

How to: Prevent Automatic Power Down

How to: Suspend the Device

Managing Variables, Stacks, and Heaps on Mobile Devices

Memory and Power Management

Memory Status and Information

System Out of Memory Dialog Box

Send feedback on this topic to the authors.

© 2005 Microsoft Corporation. All rights reserved.