Click here to Skip to main content
Click here to Skip to main content

How to get individual process memory usage statistics in Windows Mobile

, 29 Oct 2010
Rate this:
Please Sign up or sign in to vote.
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Paul Heil
Software Developer (Senior) An engineering firm in Cedar Rapids, Iowa
United States United States
I'm also on the MSDN forums
http://social.msdn.microsoft.com/profile/paulh79

Comments and Discussions

 
GeneralReason for my vote of 4 could be more complete, showing the ... PinmemberFarlop28-Feb-12 4:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 30 Oct 2010
Article Copyright 2010 by Paul Heil
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid