Is
GetMemoryStatus()
not granular enough for you? Want to know how much memory is being used by each process in your Windows Mobile device? Then you want
CeGetProcVMInfo()
. This provides the same memory usage information you see in Task-Manager.
If you have platform builder, include
pkfuncs.h. If not, do some Internet searching to get the definitions you need. (It really just wraps a call to the kernel ioctl
IOCTL_KLIB_GETPROCMEMINFO
)
Windows Mobile has
32 process slots, we call it once for each possible slot. However, slot 0 is a duplicate of our current process slot and will just return an error code and slot 1 is for "execute in place" DLLs, so we can skip those. If it returns
FALSE
that probably just means there's no process running in that slot.
DWORD total = 0;
for( int idx = 2; idx < 33; ++idx )
{
PROCVMINFO vmi = { 0 };
if( ::CeGetProcVMInfo( idx, sizeof( PROCVMINFO ), &vmi ) )
{
NKDbgPrintfW( L"%d: %d bytes\r\n", idx, vmi.cbRwMemUsed );
total += vmi.cbRwMemUsed;
}
}
NKDbgPrintfW( L"Total: %d bytes\r\n", total );
For me, this prints:
2: 5,812,224 bytes
3: 327,680 bytes
4: 610,304 bytes
5: 1,409,024 bytes
6: 1,028,096 bytes
7: 765,952 bytes
8: 36,864 bytes
9: 450,560 bytes
10: 438,272 bytes
11: 69,632 bytes
12: 245,760 bytes
13: 253,952 bytes
14: 831,488 bytes
15: 122,880 bytes
16: 606,208 bytes
17: 139,264 bytes
18: 266,240 bytes
19: 1,007,616 bytes
20: 1,273,856 bytes
21: 180,224 bytes
22: 73,728 bytes
Total: 15,949,824 bytes
If you want to relate that process index to something useful (like the name of the executable), you can use
GetProcessIDFromIndex()
and match it to the
th32ProcessID
member of the
PROCESSENTRY32
structure returned by the
ToolHelper API.
Enjoy!
-PaulH