Package com.google.code.externalsorting
Class StringSizeEstimator
java.lang.Object
com.google.code.externalsorting.StringSizeEstimator
Simple class used to estimate memory usage.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static int
private static int
private static boolean
private static int
private static int
private static int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent instantiation. -
Method Summary
-
Field Details
-
OBJ_HEADER
private static int OBJ_HEADER -
ARR_HEADER
private static int ARR_HEADER -
INT_FIELDS
private static int INT_FIELDS -
OBJ_REF
private static int OBJ_REF -
OBJ_OVERHEAD
private static int OBJ_OVERHEAD -
IS_64_BIT_JVM
private static boolean IS_64_BIT_JVM
-
-
Constructor Details
-
StringSizeEstimator
private StringSizeEstimator()Private constructor to prevent instantiation.
-
-
Method Details
-
estimatedSizeOf
Estimates the size of aString
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.
-