Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Per process memory usage

34 views
Skip to first unread message

Bill T

unread,
Oct 8, 2007, 10:22:45 PM10/8/07
to
We would like to create a utility to report the amount of memory used by
each executing process but have been unable to find suitable api's. I know
various pocketpc tools provide this information and suspect that the api's
may be part of toolhelp. Has anyone done this? what api's are used?


Ross Jordan [MSFT]

unread,
Oct 8, 2007, 11:54:35 PM10/8/07
to
If you're looking for physical memory usage (which wouldn't be process
specific), you can use GlobalMemoryStatus. To calculate per process virtual
memory use, you can use VirtualQuery (or VirtualQueryEx on CE6) and walk
through the memory.

-Ross

"Bill T" <bil...@charter.net> wrote in message
news:O4HCJth...@TK2MSFTNGP02.phx.gbl...

Wes B [MSFT]

unread,
Oct 9, 2007, 4:14:00 PM10/9/07
to
depending on your requirements you may be able to use the already written
tools at your VS/PB shell. They are "mi full" and "devhealth".

http://channel9.msdn.com/wiki/default.aspx/CeDeveloper.BSPVMOptimization

--

Wes B [MSFT]

Bill T

unread,
Oct 30, 2007, 8:41:02 AM10/30/07
to
Ross

I have looked at this a bit and written sample code that steps through the
memory in each process slot. Simply checking whether memory is free,
reserved or committed and summing the respective types reports usages that
are obviously not correct.

Any suggestions on how to identify virtual memory for code, heap and/or stack?

Ross Jordan [MSFT]

unread,
Oct 30, 2007, 7:23:35 PM10/30/07
to
You might be able to use the following:

for (addr = 0x10000; addr < 32*1024*1024; addr += (DWORD)RegionSize) {
if (!VirtualQuery((LPCVOID)addr,&mbi,sizeof(mbi)))
break;
if (mbi.State == MEM_FREE)
dwAvailVirtual += (RegionSize -
((~(DWORD)BaseAddress+1)&0xffff)) & 0xffff0000;
}

You can identify some areas of memory by memory map location, or through
some of the tool help apis, but I don't know a generic way to cover all
cases. The code above should work to sum up the slot 0 memory. You'll have
to adapt it to run on different processes/slots.

-Ross

"Bill T" <Bi...@discussions.microsoft.com> wrote in message
news:F914670E-A18A-4349...@microsoft.com...

Bill T

unread,
Oct 31, 2007, 6:25:16 PM10/31/07
to
Ross

Thanks for the reply.

My sample code is similar to this but the MEM_FREE sum is way too large and
the MEM_RESERVE and MEM_COMMIT sums are way to low for the processes that I
am monitoring.

"Ross Jordan [MSFT]" <ross.nosp...@microsoft.com> wrote in message
news:4727bcfd$1...@news.microsoft.com...

Ross Jordan [MSFT]

unread,
Nov 2, 2007, 1:57:24 AM11/2/07
to
Look at the way the code below works -- I know it works correctly. BTW,
there's a couple typos in it [RegionSize, BaseAddress should be prefixed by
mbi.]

-Ross

"Bill T" <bil...@charter.net> wrote in message

news:uT8OrzAH...@TK2MSFTNGP05.phx.gbl...

0 new messages