GPT答: |
7i24.cn
|
的代码
package main
import (
"fmt"
"syscall"
"unsafe"
"runtime"
)
func main() {
var ramstatistics syscall.MemoryStatusEx
// 获取windows系统内存信息
ramstatistics.Length = uint32(unsafe.Sizeof(ramstatistics))
// 调用Windows API
syscall.GlobalMemoryStatusEx(&ramstatistics)
// 将当前内存状态输出
fmt.Printf("物理内存:")
fmt.Printf("%dKB 可用, %d KB 总共\n",ramstatistics.AvailPhys/1024, ramstatistics.TotalPhys/1024)
fmt.Printf("虚拟内存:")
fmt.Printf("%dKB 可用, %d KB 总共\n",ramstatistics.AvailVirtual/1024, ramstatistics.TotalVirtual/1024)
// 获取本goroutine使用内存
mem := new(runtime.MemStats)
runtime.ReadMemStats(mem)
fmt.Printf("本goroutine使用内存: %d KB \n", mem.Sys/1024)
}
|