Class StringSizeEstimator


  • public final class StringSizeEstimator
    extends java.lang.Object
    Simple class used to estimate memory usage.
    Author:
    Eleftherios Chetzakis
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long estimatedSizeOf​(java.lang.String s)
      Estimates the size of a String object in bytes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • estimatedSizeOf

        public static long estimatedSizeOf​(java.lang.String s)
        Estimates the size of a String object in bytes. This function was designed with the following goals in mind (in order of importance) : First goal is speed: this function is called repeatedly and it should execute in not much more than a nanosecond. Second goal is to never underestimate (as it would lead to memory shortage and a crash). Third goal is to never overestimate too much (say within a factor of two), as it would mean that we are leaving much of the RAM underutilized.
        Parameters:
        s - The string to estimate memory footprint.
        Returns:
        The estimated size in bytes.