Practical Usage of Virtual Memory
I have used the code
MEMORYSTATUSEX memInfo;
memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo);
DWORDLONG totalVirtualMem = memInfo.ullTotalPageFile;
DWORDLONG virtualMemUsed = memInfo.ullTotalPageFile - memInfo.ullAvailPageFile;
DWORDLONG totalPhysMem = memInfo.ullTotalPhys;
provided at here
Output is like: 2.3GB.
totalVirtualMem = 8.5 Gb
virtualMemUsed = 2.3 Gb
totalPhysMem = 4 Gb
Does this means that my program requires 2.3Gb of memory? Could you also comment on total virtual memory and RAM? Also I was not able to run this code:
PROCESS_MEMORY_COUNTERS_EX pmc;
GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
SIZE_T virtualMemUsedByMe = pmc.PrivateUsage;
as it gives error as,
error C2664: 'GetProcessMemoryInfo' : cannot convert parameter 2 from 'PROCESS_MEMORY_COUNTERS_EX *' to 'PPROCESS_MEMORY_COUNTERS'
I stumbled upon exactly the same Problem and found out that a simple type cast solved it for me.
PROCESS_MEMORY_COUNTERS_EX pmc;
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
SIZE_T virtualMemUsedByMe = pmc.PrivateUsage;
The solution is also described here (msdn: Question about GetProcessMemoryInfo).
链接地址: http://www.djcxy.com/p/35056.html上一篇: TStringList和TThread不释放所有内存
下一篇: 虚拟内存的实际使用