How to determine a process "virtual size" (WinXP)?
Asked Answered
W

6

10

I have a program that needs a lot of memory, and it crashes as soon as the 2GB virtual address space is reached. Sysinternals process explorer displays this as "virtual size" column. How can I determine this "virtual size" with C (or C++) code?

Ok, I have to query a performance counter for "Virtual Bytes". Perfmon shows the query string (or how it is called) as, for example, '\Process(firefox)\Virtuelle Größe' on my German Win XP installation.

How do I determine the query string for the 'current process', and is there a non-localized name for it?

Weeds answered 14/2, 2009 at 9:16 Comment(0)
C
9

According to MSDN: Memory Performance Information PROCESS_MEMORY_COUNTERS_EX.PrivateUsage is the same as VM Size in Task Manager in Windows XP. GetProcessMemoryInfo should work:

PROCESS_MEMORY_COUNTERS_EX pmcx = {};
pmcx.cb = sizeof(pmcx);
GetProcessMemoryInfo(GetCurrentProcess(),
    reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmcx), pmcx.cb);

Now pmcx.PrivateUsage holds the VM Size of the process.

Controversy answered 14/2, 2009 at 9:57 Comment(4)
I guess this will be what ProcessExplorer displays in the 'private bytes' column, so it is not what I am looking for.Weeds
PROCESS_MEMORY_COUNTERS_EX.PrivateUsage is the same as VM Size in Task Manager according to msdn.microsoft.com/en-us/library/aa965225(VS.85).aspx.Controversy
While the VM Size also is not what I'm looking for the MSDN page you mentioned has what I need: MEMORYSTATUSEX.ullTotalVirtual–MEMORYSTATUSEX.ullAvailVirtualWeeds
We needed the same Process-Explorer like "virtual size", as that was the measure that predicted failure. Can confirm that: MEMORYSTATUSEX.ullTotalVirtual–MEMORYSTATUSEX.ullAvailVirtual Gives the same figures.Jejune
K
1

You query a performance counter.
There is a complete API for this in the win32 API, read about it here.
You can look at all the performance counters if you run a program called 'perfmon.exe'

Knout answered 14/2, 2009 at 9:20 Comment(0)
O
1

You can use a performance counter. The Process Object has a "Virtual Bytes" value.

Obtund answered 14/2, 2009 at 9:26 Comment(1)
IIUC, GetProcessMemoryInfo doesn't provide this information.Weeds
S
1

I needed the same thing as theller, but unfortunately needed it for a process other than my own. Because of this, theller's self-answer of using "MEMORYSTATUSEX.ullTotalVirtual–MEMORYSTATUSEX.ullAvailVirtual" didn't work for me, since GlobalMemoryStatusEx() (the function that returns MEMORYSTATUXEX) only works for the current process.

So far, I've been unable to find exactly what I was looking for without using performance counters (I didn't get into those because they looked way more complex than what I was looking for). I got very close by looping around and using "VirtualQueryEx" to explore the address space of the desired process, counting up all of the regions that didn't have a State of MEM_FREE. In my tests, it seemed to be a constant 17M higher than I would have expected when comparing to Process Explorer. ...also, it is certainly not race-condition free.

Anyway, I know this is sorta a non-answer, but I figured I'd at least document the progress I'd made on this for whoever stumbles upon this next.

Shepperd answered 4/11, 2009 at 17:36 Comment(1)
I've been trying to figure out the same thing. Apart from adding a message pipe or window message to the other process that I'm monitoring, I'm fresh out of ideas.Amyl
W
0

In 32bit WindowsXP address space is divided in two 2GB parts: one part for the program and the other for the kernel. You can increase application part to 3GB using the /3GB switch in the boot.ini file.

Wachter answered 14/2, 2009 at 9:27 Comment(1)
I know that. The question is, how far away am I from the limit.Weeds
S
0

You don't need performance counters. Just use NAPI (Win32 FAQ)

see on win32 group news://nntp.aioe.org/comp.os.ms-windows.programmer.win32 for C code.

Skindive answered 14/2, 2009 at 12:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.