Obtaining the Current Memory Status

The function GlobalMemoryStatus can be used to return information about thecurrent memory usage for Windows CE—the information is returned in a MEMORYSTATUS structure, as shown in Listing 12.2.

Listing 12.2. Displaying memory usage with GlobalMemoryStatus
void Listing12_2()
{
  MEMORYSTATUS ms;
  ms.dwLength = sizeof(ms);
  GlobalMemoryStatus(&ms);
  cout ≪ _T("Total Phys: ") ≪ ms.dwTotalPhys ≪ endl;
  cout ≪ _T("Avail Phys:") ≪ ms.dwAvailPhys ≪ endl;
  cout ≪ _T("Total Page: ")
       ≪ ms.dwTotalPageFile ≪ endl;
  cout ≪ _T("Avail Page: ")
       ≪ ms.dwAvailPageFile ≪ endl;
  cout ≪ _T("Total Virtual: ")
       ≪ ms.dwTotalVirtual ≪ endl;
  cout ≪ _T("Avail Virtual: ")
       ≪ ms.dwAvailVirtual ≪ endl;
}

Typical output for a Windows CE device looks like the following:

Total Phys: 8301568
Avail Phys: 6810624
Total Page: 0
Avail Page: 0
Total Virtual: 33554432
Avail Virtual: 29949952

In this case, the device has 8 MB (8301568 bytes) of memory set aside for program execution, of which around 6 MB (6810624 bytes) is available. Note that this function does not take into account the amount of memory set aside for the object store. The dwTotalPageFile and dwAvailPageFile always return 0 under Windows CE, since the operating system does not use a paging file, and data storage is allocated directly from memory. The dwTotalVirtual member returns the total number of bytes of virtual address space available to the process, which is 32 MB, or 33554432 bytes. Of this, 29949952 bytes of address space are still available for use. The information returned under emulation is much the same except that the total physical and available physical memory size is always returned as 16777216, or 16 MB.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.107.241