Share via


How to: Determine Available Memory

4/19/2010

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

    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);

Remarks

Note

GetStoreInformation is deprecated. Use GetDiskFreeSpaceEx instead.

See Also

Concepts

Handling Application Hibernation
Handling Low Memory States
How to: Determine Battery Status
Preventing Automatic Power Down
How to: Program an Application for Windows Mobile Standard to Turn the Backlight On or Off
How to: Suspend the Device
Managing Variables, Stacks, and Heaps on Windows Mobile Devices
Getting Memory Status and Processor Information
System Out of Memory Dialog Box

Other Resources

Memory and Power Management