限制内存缓存最大容量为系统内存的三分之一

This commit is contained in:
刘祥超
2023-10-16 14:28:07 +08:00
parent 3909695b44
commit 2acf890b8e
3 changed files with 24 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ import (
)
var systemTotalMemory = -1
var systemMemoryBytes uint64
func init() {
if !teaconst.IsMain {
@@ -29,7 +30,9 @@ func SystemMemoryGB() int {
return 1
}
systemTotalMemory = int(stat.Total / (1<<30))
systemMemoryBytes = stat.Total
systemTotalMemory = int(stat.Total / (1 << 30))
if systemTotalMemory <= 0 {
systemTotalMemory = 1
}
@@ -38,3 +41,8 @@ func SystemMemoryGB() int {
return systemTotalMemory
}
// SystemMemoryBytes 系统内存总字节数
func SystemMemoryBytes() uint64 {
return systemMemoryBytes
}