0

我想计算系统的总物理内存使用量。这是我的代码:

float totalmem(){

    DWORDLONG totalVirtualMem;
    MEMORYSTATUSEX memInfo;
    float virtualMemUsed;

    memInfo.dwLength = sizeof(MEMORYSTATUSEX);
    GlobalMemoryStatusEx(&memInfo);
    totalVirtualMem = memInfo.ullTotalPageFile;
    virtualMemUsed = (double) (memInfo.ullTotalPageFile - memInfo.ullAvailPageFile) / memInfo.ullTotalPageFile * 100;
    return virtualMemUsed;
}

但答案与 Windows 任务管理器或进程资源管理器显示的不同。我的代码有什么问题?

4

1 回答 1

0

正确的代码:

float totalmem(){

DWORDLONG totalVirtualMem;
MEMORYSTATUSEX memInfo;
float virtualMemUsed;

memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo);
//totalVirtualMem = memInfo.ullTotalPageFile;
virtualMemUsed = (double) (memInfo.ullTotalPhys - memInfo.ullAvailPhys) / memInfo.ullTotalPhys * 100;
return virtualMemUsed;
}
于 2012-07-30T09:00:22.080 回答