javax.realtime
Class SizeEstimator

java.lang.Object
  extended by javax.realtime.SizeEstimator

public final class SizeEstimator
extends java.lang.Object

This class maintains an estimate of the amount of memory required to store a set of objects.

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. If the instance itself is allocated in several parts (if 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.

See Also:
MemoryArea.MemoryArea(SizeEstimator), LTMemory.LTMemory(SizeEstimator, SizeEstimator), VTMemory.VTMemory(SizeEstimator, SizeEstimator)

Constructor Summary
SizeEstimator()
           
 
Method Summary
 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)
          Take into account additional number instances of Class c when estimating the size of the MemoryArea.
 void reserve(SizeEstimator size)
          Take into account an additional instance of SizeEstimator size when estimating the size of the MemoryArea.
 void reserve(SizeEstimator estimator, int number)
          Take into account additional number instances of SizeEstimator size when estimating the size of the MemoryArea.
 void reserveArray(int length)
          Take 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)
          Take into account an additional instance of an array of length primitive values when estimating the size of the MemoryArea.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SizeEstimator

public SizeEstimator()
Method Detail

reserve

public void reserve(java.lang.Class c,
                    int number)
Take into account additional number instances of Class c when estimating the size of the MemoryArea.

Parameters:
c - The class to take into account.
number - The number of instances of c to estimate.
Throws:
java.lang.IllegalArgumentException - Thrown if c is null.

reserve

public void reserve(SizeEstimator estimator,
                    int number)
Take into account additional number instances of SizeEstimator size when estimating the size of the MemoryArea.

Parameters:
estimator - The given instance of SizeEstimator.
number - The number of times to reserve the size denoted by estimator.
Throws:
java.lang.IllegalArgumentException - Thrown if estimator is null.

reserve

public void reserve(SizeEstimator size)
Take into account an additional instance of SizeEstimator size when estimating the size of the MemoryArea.

Parameters:
size - The given instance of SizeEstimator.
Throws:
java.lang.IllegalArgumentException - Thrown if size is null.

reserveArray

public void reserveArray(int length)
Take into account an additional instance of an array of length reference values when estimating the size of the MemoryArea.

Parameters:
length - The number of entries in the array.
Throws:
java.lang.IllegalArgumentException - Thrown if length is negative.
Since:
1.0.1

reserveArray

public void reserveArray(int length,
                         java.lang.Class type)
Take into account an additional instance of an array of 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.

Parameters:
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.
Throws:
java.lang.IllegalArgumentException - Thrown if length is negative, or type does not represent a primitive type.
Since:
1.0.1

getEstimate

public long getEstimate()
Gets an estimate of the number of bytes needed to store all the objects reserved.

Returns:
The estimated size in bytes.