public final class SizeEstimator
extends java.lang.Object
SizeEstimator
is a floor on the amount of memory
that should be allocated. Many objects allocate other objects when
they are constructed. SizeEstimator
only estimates the
memory requirement of the object itself, it does not include memory
required for any objects allocated at construction time. When the
instance itself is allocated in several parts (when for instance the
object and its monitor are separate), the size estimate shall
include the sum of the sizes of all the parts that are allocated
from the same memory area as the instance.
Alignment considerations, and possibly other order-dependent issues may cause the allocator to leave a small amount of unusable space, consequently the size estimate cannot be seen as more than a close estimate.
MemoryArea(SizeEstimator)
Constructor and Description |
---|
SizeEstimator()
Create an empty size estimator.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Restores the estimate value to zero for reuse.
|
long |
getEstimate()
Gets an estimate of the number of bytes needed to store
all the objects reserved.
|
void |
reserve(java.lang.Class<?> c,
int number)
Takes into account additional
number instances of
Class c when estimating the size of the
MemoryArea . |
void |
reserve(SizeEstimator size)
Takes into account an additional estimation from the instance of
SizeEstimator
size when estimating the size of the
MemoryArea . |
void |
reserve(SizeEstimator estimator,
int number)
Takes into account additional
number of the estimations from
instances of SizeEstimator size when estimating the size
of the MemoryArea . |
void |
reserveArray(int length)
Takes into account an additional instance of an array of
length
reference values when estimating the size of the MemoryArea . |
void |
reserveArray(int length,
java.lang.Class<?> type)
Takes into account an additional instance of an array of
length
primitive values when estimating the size of the MemoryArea . |
void |
reserveLambda()
Determines the size of a lambda with no
closure and add it to this size estimator.
|
void |
reserveLambda(EnclosedType first)
Determines the size of a lambda with one variable in its
closure and add it to this size estimator.
|
void |
reserveLambda(EnclosedType first,
EnclosedType second)
Determines the size of a lambda with two variables in its
closure and add it to this size estimator.
|
void |
reserveLambda(EnclosedType first,
EnclosedType second,
EnclosedType... others)
Determines the size of a lambda with more than two variables in its
closure and add it to this size estimator.
|
public void reserve(java.lang.Class<?> c, int number)
number
instances of
Class c
when estimating the size of the
MemoryArea
.c
- The class to take into account.number
- The number of instances of c
to estimate.StaticIllegalArgumentException
- when c
is null
or
number
is negative.StaticIllegalArgumentException
also when
number
is less than zero.public void reserve(SizeEstimator estimator, int number)
number
of the estimations from
instances of SizeEstimator size
when estimating the size
of the MemoryArea
.estimator
- The given instance of SizeEstimator
.number
- The number of times to reserve the size denoted by
estimator
.StaticIllegalArgumentException
- when estimator
is
null
or number
is less than zero.StaticIllegalArgumentException
also when
number
is less than zero.public void reserve(SizeEstimator size)
size
when estimating the size of the
MemoryArea
.size
- The given instance of SizeEstimator
.StaticIllegalArgumentException
- when size
is null
.public void reserveArray(int length)
length
reference values when estimating the size of the MemoryArea
.length
- The number of entries in the array.StaticIllegalArgumentException
- when length
is negative.public void reserveArray(int length, java.lang.Class<?> type)
length
primitive values when estimating the size of the MemoryArea
.
Class values for the primitive types are available from the corresponding class types; e.g., Byte.TYPE, Integer.TYPE, and Short.TYPE.
length
- The number of entries in the array.type
- The class representing a primitive type. The
reservation will leave room for an array of length
of
the primitive type corresponding to type
.StaticIllegalArgumentException
- when length
is negative,
or type
does not represent a primitive type.public void reserveLambda(EnclosedType first, EnclosedType second, EnclosedType... others)
first
- Type of first variable in closure.second
- Type of second variable in closure.others
- Types of additional variables in closure.public void reserveLambda(EnclosedType first, EnclosedType second)
first
- Type of first variable in closure.second
- Type of second variable in closure.public void reserveLambda(EnclosedType first)
first
- Type of first variable in closure.public void reserveLambda()
public long getEstimate()
public void clear()