windows 如何确定进程“虚拟大小”(WinXP)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/548819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to determine a process "virtual size" (WinXP)?
提问by theller
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?
我有一个需要大量内存的程序,一旦达到 2GB 虚拟地址空间它就会崩溃。Sysinternals 进程资源管理器将此显示为“虚拟大小”列。如何使用 C(或 C++)代码确定这个“虚拟大小”?
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.
好的,我必须查询“虚拟字节”的性能计数器。Perfmon 在我的德语 Win XP 安装中将查询字符串(或它的调用方式)显示为例如 '\Process(firefox)\Virtuelle Gr??e'。
How do I determine the query string for the 'current process', and is there a non-localized name for it?
如何确定“当前进程”的查询字符串,是否有非本地化名称?
采纳答案by dalle
According to MSDN: Memory Performance InformationPROCESS_MEMORY_COUNTERS_EX.PrivateUsage
is the same as VM Size in Task Manager in Windows XP. GetProcessMemoryInfoshould work:
根据MSDN:内存性能信息PROCESS_MEMORY_COUNTERS_EX.PrivateUsage
与 Windows XP 中任务管理器中的 VM 大小相同。GetProcessMemoryInfo应该可以工作:
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.
现在pmcx.PrivateUsage
保存进程的 VM 大小。
回答by dianders
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.
我需要与 ller 相同的东西,但不幸的是,我需要它来处理我自己以外的过程。因此,ller 使用“MEMORYSTATUSEX.ullTotalVirtual–MEMORYSTATUSEX.ullAvailVirtual”的自我回答对我不起作用,因为 GlobalMemoryStatusEx()(返回 MEMORYSTATUXEX 的函数)仅适用于当前进程。
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.
到目前为止,我一直无法在不使用性能计数器的情况下准确找到我正在寻找的内容(我没有深入了解它们,因为它们看起来比我正在寻找的要复杂得多)。我通过循环并使用“VirtualQueryEx”来探索所需进程的地址空间,计算所有没有 MEM_FREE 状态的区域,从而非常接近。在我的测试中,与 Process Explorer 相比,它似乎比我预期的高 17M。...此外,它肯定不是无竞争条件的。
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.
无论如何,我知道这有点无法回答,但我想我至少会记录下我在这方面取得的进展,以便接下来遇到这个问题的人。
回答by shoosh
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'
您查询性能计数器。
在 win32 API 中有一个完整的 API,请在此处阅读。
如果您运行名为“perfmon.exe”的程序,您可以查看所有性能计数器
回答by Assaf Lavie
回答by Kasprzol
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.
在 32 位 WindowsXP 中,地址空间分为两个 2GB 的部分:一部分用于程序,另一部分用于内核。您可以使用boot.ini 文件中的/3GB 开关将应用程序部分增加到 3GB 。
回答by Kasprzol
You don't need performance counters. Just use NAPI (Win32 FAQ)
您不需要性能计数器。只需使用 NAPI (Win32 FAQ)
see on win32 group news://nntp.aioe.org/comp.os.ms-windows.programmer.win32 for C code.
有关 C 代码,请参见 win32 组新闻://nntp.aioe.org/comp.os.ms-windows.programmer.win32。