org.apache.lucene.util

Class RamUsageEstimator

    • Method Detail

      • sizeOf

        public static long sizeOf(Long value)
        Return the size of the provided Long object, returning 0 if it is cached by the JVM and its shallow size otherwise.
      • sizeOf

        public static long sizeOf(byte[] arr)
        Returns the size in bytes of the byte[] object.
      • sizeOf

        public static long sizeOf(boolean[] arr)
        Returns the size in bytes of the boolean[] object.
      • sizeOf

        public static long sizeOf(char[] arr)
        Returns the size in bytes of the char[] object.
      • sizeOf

        public static long sizeOf(short[] arr)
        Returns the size in bytes of the short[] object.
      • sizeOf

        public static long sizeOf(int[] arr)
        Returns the size in bytes of the int[] object.
      • sizeOf

        public static long sizeOf(float[] arr)
        Returns the size in bytes of the float[] object.
      • sizeOf

        public static long sizeOf(long[] arr)
        Returns the size in bytes of the long[] object.
      • sizeOf

        public static long sizeOf(double[] arr)
        Returns the size in bytes of the double[] object.
      • shallowSizeOf

        public static long shallowSizeOf(Object[] arr)
        Returns the shallow size in bytes of the Object[] object.
      • shallowSizeOf

        public static long shallowSizeOf(Object obj)
        Estimates a "shallow" memory usage of the given object. For arrays, this will be the memory taken by array storage (no subreferences will be followed). For objects, this will be the memory taken by the fields. JVM object alignments are also applied.
      • shallowSizeOfInstance

        public static long shallowSizeOfInstance(Class<?> clazz)
        Returns the shallow instance size in bytes an instance of the given class would occupy. This works with all conventional classes and primitive types, but not with arrays (the size then depends on the number of elements and varies from object to object).
        Throws:
        IllegalArgumentException - if clazz is an array class.
        See Also:
        shallowSizeOf(Object)
      • humanReadableUnits

        public static String humanReadableUnits(long bytes)
        Returns size in human-readable units (GB, MB, KB or bytes).