我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何在GO中获取总内存/ RAM?

How can I get the total amount of memory/RAM attached to a system in Go? I want to use native code only if possible. I have found a library that wraps linux sysinfo command. Is there a more elegant way?

Besides runtime.MemStats you can use gosigar to monitor system memory.

cgo & linux solution

package main

// #include <unistd.h>
import "C"

func main() {
    println(C.sysconf(C._SC_PHYS_PAGES)*C.sysconf(C._SC_PAGE_SIZE), " bytes")
}

近期文章

  • 在Go中等效于setdefault?
  • len()运行多少次?
  • Golang:交换两个数字的接口
  • 如何解析mysql错误golang
  • 在Go中设置进程名称(如ps所示)
  • 尝试从Go程序中启动外部编辑器
  • golang:运行时错误:无效的内存地址或nil指针取消引用
  • 如何在Go中解析HTTP标头
  • golang按时设置值
  • Go-多个文件的formFile
  • 访问golang中的未导出字段/反射?
  • 为什么不正确地终止子进程?
  • (gcc)go中的打包结构
  • 字符串和并发性的不变性
  • 如何在Go中动态频道列表中选择输入?
  • golang如何现场测试http服务器?
  • 有计划开发golang版本的Android吗?
  • Golang函数参数无类型?
  • 精确的gccgo
  • 未定义:proto.ProtoPackageIsVersion3

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华