如何在 Windows 上获取可用内存? [英] How to get available RAM on Windows?

查看:27
本文介绍了如何在 Windows 上获取可用内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找返回可用内存的方法,目前我只找到了这个答案

I am looking for method that return available RAM and for this moment I have found only this answer

https://stackoverflow.com/a/2513561/5709159

#include <windows.h>

unsigned long long getTotalSystemMemory()
{
    MEMORYSTATUSEX status;
    status.dwLength = sizeof(status);
    GlobalMemoryStatusEx(&status);
    return status.ullTotalPhys;
}

但是这个方法返回总内存.所以,我需要找出如何获取当前正在使用的 RAM 或方法,而不是直接返回可用的 RAM.

But this method return Total memory. So, I need to find out how to get RAM that currently in usage or method than directly return available RAM.

怎么做?

编辑

我需要知道可用 RAM 的数量才能将其显示在我的统计表格中.我有一个字段 Available RAM :

I need to know amount of available RAM in order to present it on my statistic form. I have a field Available RAM :

推荐答案

您可以使用对 GlobalMemoryStatusEx() 的相同调用并检查 .ullAvailPhys 字段一个 href="https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex" rel="nofollow noreferrer">MEMORYSTATUSEX 结构来获取数量可用的物理内存.此值与 .ullTotalPhys 值之间的区别在于使用了多少物理内存.

You can use the same call to GlobalMemoryStatusEx() and examine the .ullAvailPhys field of the MEMORYSTATUSEX structure to get the amount of available physical memory. The difference between this and the .ullTotalPhys value will be how much physical memory is in use.

这篇关于如何在 Windows 上获取可用内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆