memutils

package
v0.0.0-...-98f1bff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2025 License: Unlicense Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemInfo

type MemInfo struct {
	Total     uint64 // 总内存(字节)
	Available uint64 // 可用内存(字节)
	Used      uint64 // 已用内存(字节)
}

MemInfo 包含系统内存信息

func GetMemInfo

func GetMemInfo() (*MemInfo, error)

GetMemInfo 获取系统内存信息

Example

ExampleGetMemInfo 展示如何使用GetMemInfo函数

memInfo, err := GetMemInfo()
if err != nil {
	fmt.Printf("获取内存信息失败: %v\n", err)
	return
}

// 计算内存使用率
usagePercent := float64(memInfo.Used) / float64(memInfo.Total) * 100

fmt.Printf("总内存: %d MB\n", memInfo.Total/1024/1024)
fmt.Printf("已用内存: %d MB\n", memInfo.Used/1024/1024)
fmt.Printf("可用内存: %d MB\n", memInfo.Available/1024/1024)
fmt.Printf("内存使用率: %.2f%%\n", usagePercent)

// 输出不确定,所以不做验证

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL