Record Class MemoryInfo
java.lang.Object
java.lang.Record
cloud.opencode.base.core.system.MemoryInfo
- Record Components:
total- total memory in bytes - 总内存(字节)used- used memory in bytes - 已用内存(字节)free- free memory in bytes - 空闲内存(字节)max- maximum memory in bytes, -1 if undefined - 最大内存(字节),未定义时为 -1
Immutable snapshot of memory information.
内存信息的不可变快照。
Represents a point-in-time view of memory usage, applicable to both JVM heap/non-heap memory and physical system memory.
表示内存使用情况的时间点视图,适用于 JVM 堆/非堆内存和物理系统内存。
Usage Examples | 使用示例:
MemoryInfo heap = SystemInfo.heapMemory();
System.out.println("Heap used: " + heap.usedDisplay());
System.out.println("Usage: " + heap.usagePercent() + "%");
MemoryInfo physical = SystemInfo.memory();
System.out.println("Physical total: " + physical.totalDisplay());
- Since:
- JDK 25, opencode-base-core V1.0.3
- Author:
- Leon Soo
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMemoryInfo(long total, long used, long free, long max) Compact canonical constructor with validation. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.longfree()Returns the value of thefreerecord component.Returns a human-readable representation of free memory.final inthashCode()Returns a hash code value for this object.longmax()Returns the value of themaxrecord component.static MemoryInfoof(long total, long used, long free, long max) Creates a MemoryInfo with the given values.static MemoryInfoofPhysical(long total, long free) Creates a MemoryInfo for physical memory where max equals total.final StringtoString()Returns a string representation of this record class.longtotal()Returns the value of thetotalrecord component.Returns a human-readable representation of total memory.doubleReturns the memory usage percentage (used/total * 100).longused()Returns the value of theusedrecord component.Returns a human-readable representation of used memory.
-
Constructor Details
-
MemoryInfo
public MemoryInfo(long total, long used, long free, long max) Compact canonical constructor with validation. 带验证的紧凑规范构造器。
-
-
Method Details
-
of
Creates a MemoryInfo with the given values. 使用给定值创建 MemoryInfo。- Parameters:
total- total bytes - 总字节数used- used bytes - 已用字节数free- free bytes - 空闲字节数max- max bytes (-1 if undefined) - 最大字节数(未定义时为 -1)- Returns:
- a new MemoryInfo instance
-
ofPhysical
Creates a MemoryInfo for physical memory where max equals total. 为物理内存创建 MemoryInfo,其中 max 等于 total。- Parameters:
total- total physical memory bytes - 总物理内存字节数free- free physical memory bytes - 空闲物理内存字节数- Returns:
- a new MemoryInfo instance
-
usagePercent
public double usagePercent()Returns the memory usage percentage (used/total * 100). 返回内存使用百分比(used/total * 100)。- Returns:
- usage percentage in range [0.0, 100.0], or 0.0 if total is 0
-
totalDisplay
Returns a human-readable representation of total memory. 返回总内存的可读表示。- Returns:
- formatted string e.g. "16.0 GB"
-
usedDisplay
Returns a human-readable representation of used memory. 返回已用内存的可读表示。- Returns:
- formatted string e.g. "8.5 GB"
-
freeDisplay
Returns a human-readable representation of free memory. 返回空闲内存的可读表示。- Returns:
- formatted string e.g. "7.5 GB"
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
total
-
used
-
free
-
max
-