为什么 FreePhysicalMemory 给出的值不正确? [英] Why is FreePhysicalMemory giving an incorrect value?

查看:61
本文介绍了为什么 FreePhysicalMemory 给出的值不正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 win32_OperatingSystem 类中的 FreePhysicalMemory 属性.问题是,它通常只返回几 MB 的值.显然,考虑到我的计算机上只打开了 Powershell,我有更多可用的 RAM.

I am trying to use the FreePhysicalMemory property from the win32_OperatingSystem class. The problem is, it usually returns a value of only a few MB. Clearly, I have more RAM avalible to me considering the fact that only Powershell is open on my computer.

我正在使用以下代码:

$test = gwmi win32_OperatingSystem
$test.FreePhysicalMemory

我做错了吗?或者我不明白 FreePhysicalMemory 属性实际返回什么?

Am I doing something wrong? Or do I not understand what the FreePhysicalMemory property actually returns?

感谢您的帮助.

推荐答案

能否请您提供一些其他详细信息,例如您的操作系统、您的总物理内存是多少,以及 PowerShell 命令的实际输出?

Can you please provide some additional details, such as your operating system, what your total physical memory is, and the actual output from the PowerShell command?

在使用 win32_OperatingSystem 类时要记住的一件事是,FreePhysicalMemory 和 FreeVirtualMemory 的值以 KB 为单位返回 - 不仅仅是字节,因此您可能需要除以 1024.

One thing to remember when using the win32_OperatingSystem class is that the values for FreePhysicalMemory and FreeVirtualMemory are returned in KB - not just bytes, so you may have have an extra division by 1024.

例如,在我的总物理内存为 4GB(WinXP 32 位 - 因此操作系统只能使用 ~3.5GB)的计算机上,这是我的 PowerShell 的输出:

For example, on my computer with 4GB total physical memory (WinXP 32-bit - so the OS can only use ~3.5GB), here is the output from my PowerShell:

$test = gwmi win32_OperatingSystem
# verify the "visible" memory size to the Operating System
$test.TotalVisibleMemorySize
3652840

# check free memory
$test.FreePhysicalMemory
1872828

# divide by 1024 twice, once for KB -> MB, once for MB -> GB
($test.FreePhysicalMemory / 1024) / 1024
1.78606796264648

我有几个应用程序在运行,但这表明我仍然有大约 1.786GB 的可用物理内存.我验证了这种行为在我的 Win7 x64 机器上也是相同的.

I have a few applications running, but that shows that I still have roughly 1.786GB of free physical memory. I verified this behavior is identical on my Win7 x64 box as well.

以下是 Win32_OperatingSystem WMI 类的 MSDN 参考页面:http://msdn.microsoft.com/en-us/library/aa394239.aspx

Here is the MSDN reference page for the Win32_OperatingSystem WMI class: http://msdn.microsoft.com/en-us/library/aa394239.aspx

这篇关于为什么 FreePhysicalMemory 给出的值不正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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