对不起,我刚刚在 x64 编译器上测试的。
32位的编译器的话,可能有点问题。Intel 自己提供的Kernel32库里,32位的结构用的一个2个4字节的成员的 type 带表示1个8字节的整数,比较麻烦。
你可以自己定义一个 My_MEMORYSTATUSEX,然后调用时给一个 T_MEMORYSTATUSEX,然后调用完转换成 My_MEMORYSTATUSEX 使用。
这些成员的含义,见以下注释。
[Fortran] 纯文本查看 复制代码 Program Main
use Kernel32
use ISO_C_Binding
Implicit None
TYPE My_MEMORYSTATUSEX
SEQUENCE
integer(DWORD) dwLength ! knowns DWORD
integer(DWORD) dwMemoryLoad ! knowns DWORD
integer(DWORDLONG) ullTotalPhys ! knowns DWORDLONG
integer(DWORDLONG) ullAvailPhys ! knowns DWORDLONG
integer(DWORDLONG) ullTotalPageFile ! knowns DWORDLONG
integer(DWORDLONG) ullAvailPageFile ! knowns DWORDLONG
integer(DWORDLONG) ullTotalVirtual ! knowns DWORDLONG
integer(DWORDLONG) ullAvailVirtual ! knowns DWORDLONG
integer(DWORDLONG) ullAvailExtendedVirtual ! knowns DWORDLONG
END TYPE
type(T_MEMORYSTATUSEX) stMemStat
type(My_MEMORYSTATUSEX) stMyMemStat
integer i
stMemStat%dwLength = c_sizeof(stMemStat)
i = GlobalMemoryStatusEx ( stMemStat )
stMyMemStat = transfer( stMemStat , stMyMemStat )
write(*,*) "There is ",stMyMemStat%dwMemoryLoad,"% percent of memory in use."!//内存使用百分比
write(*,*) "There are ",stMyMemStat%ullTotalPhys/1024," total KB of physical memory."!//物理内存总量
write(*,*) "There are ",stMyMemStat%ullAvailPhys/1024," free KB of physical memory."!//物理内存可用量
write(*,*) "There are ",stMyMemStat%ullTotalPageFile/1024," total KB of paging file."!//虚拟内存(页面文件)总量
write(*,*) "There are ",stMyMemStat%ullAvailPageFile/1024," free KB of paging file."!//虚拟内存(页面文件)可用量
write(*,*) "There are ",stMyMemStat%ullTotalVirtual/1024," total KB of virtual memory."!//虚拟地址总量,32位固定为2GB
write(*,*) "There are ",stMyMemStat%ullAvailVirtual/1024," free KB of virtual memory."!//虚拟地址可用量(可以认为这个代表可用值)
write(*,*) "There are ",stMyMemStat%ullAvailExtendedVirtual/1024," free KB of extended memory."
End Program Main |