Interface GlobalMemory

All Known Implementing Classes:
AbstractGlobalMemory, LinuxGlobalMemory, MacGlobalMemory, WindowsGlobalMemory

@PublicApi @ThreadSafe public interface GlobalMemory
The GlobalMemory class tracks information about the use of a computer's physical memory (RAM) as well as any available virtual memory.

Example: checking available memory:

GlobalMemory mem = si.getHardware().getMemory();
long totalBytes = mem.getTotal();
long availBytes = mem.getAvailable();
long usedBytes = totalBytes - availBytes;
System.out.printf("Memory: %s used / %s total%n", FormatUtil.formatBytes(usedBytes),
        FormatUtil.formatBytes(totalBytes));
For swap/virtual memory information, see getVirtualMemory().
  • Method Details

    • getTotal

      long getTotal()
      The amount of actual physical memory, in bytes.
      Returns:
      Total number of bytes.
    • getAvailable

      long getAvailable()
      The amount of physical memory currently available, in bytes.
      Returns:
      Available number of bytes.
    • getPageSize

      long getPageSize()
      The number of bytes in a memory page
      Returns:
      Page size in bytes.
    • getVirtualMemory

      VirtualMemory getVirtualMemory()
      Virtual memory, such as a swap file.

      Operating systems differ significantly in how they manage virtual memory. See the VirtualMemory class documentation for details on Windows commit-charge, Linux overcommit, and macOS compressed-memory models.

      Returns:
      A VirtualMemory object.
    • getPhysicalMemory

      List<PhysicalMemory> getPhysicalMemory()
      Physical memory, such as banks of memory.

      On Linux, requires elevated permissions. On FreeBSD and Solaris, requires installation of dmidecode.

      Returns:
      A list of PhysicalMemory objects.