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?
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.
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.
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.
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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With