Package com.complexible.common.base

# Class Memory

java.lang.Object
com.complexible.common.base.Memory

public final class Memory extends Object

Utility class for memory related information.

Since:
  2.0
Version:
  3.1.1
Author:
  Evren Sirin, Michael Grove

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `DEFAULT_PAGE_SIZE`
  `static final long`
  `GB`
  The number of bytes in a gigabyte (2^30).
  `static final long`
  `KB`
  The number of bytes in a kilobyte (2^10).
  `static final long`
  `MB`
  The number of bytes in a kilobyte (2^20).

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static long`
  `available()`
  Returns the current amount of memory available on the heap.
  `static String`
  `detailedUsage()`
  Detailed memory information logged only at TRACE level.
  `static long`
  `fromReadable(String theStr)`
  Take a representation from `readable(long)` and turn it back into bytes.
  `static String`
  `heapUsage()`
  `static long`
  `max()`
  Returns the maximum amount of memory that the JVM will attempt to use.
  `static String`
  `readable(long bytes)`
  Returns a human-readable representation of bytes similar to how "ls -h" works in Unix systems.
  `static long`
  `sizeOf(Object obj)`
  Returns the size of this object (with its references).
  `static long`
  `system()`
  Return the total memory available to the system, ie how much RAM the computer has.
  `static long`
  `total()`
  Returns the total memory available to JVM in bytes.
  `static long`
  `used()`
  Returns the used memory in bytes.
  `static long`
  `usedHeap()`
  `static long`
  `usedNonHeap()`
  `static float`
  `usedRatio()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### KB

    public static final long KB
    The number of bytes in a kilobyte (2^10).
    See Also:
      - Constant Field Values

  - ### MB

    public static final long MB
    The number of bytes in a kilobyte (2^20).
    See Also:
      - Constant Field Values

  - ### GB

    public static final long GB
    The number of bytes in a gigabyte (2^30).
    See Also:
      - Constant Field Values

  - ### DEFAULT_PAGE_SIZE

    public static final int DEFAULT_PAGE_SIZE
    See Also:
      - Constant Field Values

- ## Method Details

  - ### readable

    public static String readable(long bytes)
    Returns a human-readable representation of bytes similar to how "ls -h" works in Unix systems. The resulting is guaranteed to be 4 characters or less unless the given value is greater than 999TB. The last character in the returned string is one of 'B', 'K', 'M', 'G', or 'T' representing bytes, kilobytes, megabytes, gigabytes or terabytes. This function uses the binary unit system where 1K = 1024B.

    Examples:

                 482 = 482B
                1245 = 1.2K
              126976 = 124K
             4089471 = 3.9M
            43316209 =  41M
          1987357695 = 1.9G

  - ### fromReadable

    public static long fromReadable(String theStr)
    Take a representation from `readable(long)` and turn it back into bytes. For example, if the input is "2K" the output would be 2048.
    Parameters:
      `theStr` - the byte string
    Returns:
      the number of bytes

  - ### used

    public static long used()
    Returns the used memory in bytes. The result is an estimate and based on when the GC runs this value might change significantly.

  - ### total

    public static long total()
    Returns the total memory available to JVM in bytes. This value may change over time.

  - ### max

    public static long max()
    Returns the maximum amount of memory that the JVM will attempt to use. It is possible that

  - ### available

    public static long available()
    Returns the current amount of memory available on the heap. Shorthand for: `Memory.max() - Memory.used()`
    Returns:
      available heap memory

  - ### system

    public static long system()
    Return the total memory available to the system, ie how much RAM the computer has.
    Returns:
      the system memory.

  - ### usedRatio

    public static float usedRatio()

  - ### usedHeap

    public static long usedHeap()

  - ### usedNonHeap

    public static long usedNonHeap()

  - ### heapUsage

    public static String heapUsage()

  - ### detailedUsage

    public static String detailedUsage()
    Detailed memory information logged only at TRACE level.

  - ### sizeOf

    public static long sizeOf(Object obj)
    Returns the size of this object (with its references).