Practical use of virtual memory

I 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 here

The output is as follows: 2.3 GB.

totalVirtualMem = 8.5 Gb
virtualMemUsed  = 2.3 Gb
totalPhysMem    = 4   Gb

Does this mean that my program requires 2.3 GB of memory? Could you also comment on shared 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;

since it gives an error like,

error C2664: 'GetProcessMemoryInfo' : cannot convert parameter 2 from 'PROCESS_MEMORY_COUNTERS_EX *' to 'PPROCESS_MEMORY_COUNTERS'
+5
source share
1 answer

I came across the same problem and found out that a simple throw type solved this 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) .

+6
source

All Articles