Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 592
theller Avatar asked Feb 14 '09 09:02

theller


People also ask

What is the virtual size of a process?

Virtual size is the number of pages that the process has allocated, those pages not currently in the working set (physically loaded in RAM) will be in the system's page file. Typically you allocate memory that is not freed.

What is virtual size memory?

Virtual memory is a common technique used in a computer's operating system (OS). Virtual memory uses both hardware and software to enable a computer to compensate for physical memory shortages, temporarily transferring data from random access memory (RAM) to disk storage.

What limits the available memory for virtual users?

Virtual memory upper limits are set by the OS: eg. 32-bit Windows the limit is 16TB, and on 64-bit Windows the limit is 256TB. Max limitation is physical disk space.


2 Answers

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.

like image 108
dalle Avatar answered Oct 03 '22 08:10

dalle


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'

like image 20
shoosh Avatar answered Oct 03 '22 06:10

shoosh