org.deegree.commons.utils.memory
Class AllocatedHeapMemory

java.lang.Object
  extended by org.deegree.commons.utils.memory.AllocatedHeapMemory

public class AllocatedHeapMemory
extends Object

The AllocatedHeapMemory class provides methods for calculating the heap memory for some primitive objects.

Version:
$Revision: 22955 $, $Date: 2010-03-10 12:54:52 +0100 (Wed, 10 Mar 2010) $
Author:
Rutger Bezema, last edited by: $Author: rbezema $

Field Summary
static int DOUBLE_SIZE
          Number of bytes for a float
static int FLOAT_SIZE
          Number of bytes for a float
static int INSTANCE_SIZE
          The number of bytes a simple new Object without any fields will consume.
static int INT_SIZE
          Number of bytes for an int
static int LONG_SIZE
          Number of bytes for an int
static int REF_SIZE
          The number of bytes a reference will have
 
Constructor Summary
AllocatedHeapMemory()
           
 
Method Summary
static int instanceAndReferenceSize(boolean asReference)
          This will return the size of an instance of a new Object, if the asReference is true, the size of a reference will be added as well.
static long roundToMem(long currentSize)
          The JVM allocates 8 bytes at a time..
static long sizeOfBuffer(Buffer b, boolean asReference)
           
static long sizeOfByteArray(byte[] o, boolean asReference)
           
static long sizeOfDoubleArray(double[] o, boolean asReference)
           
static long sizeOfFloatArray(float[] o, boolean asReference)
           
static long sizeOfIntArray(int[] o, boolean asReference)
           
static long sizeOfList(List<?> l, boolean asReference)
          The size of the Objects referenced in the list are not accounted for.
static long sizeOfLongArray(int[] o, boolean asReference)
           
static long sizeOfObjectArray(Object[] o, boolean asReference)
           
static long sizeOfString(String s, boolean asReference, boolean internalised)
          The approximate size of the given String Object in bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REF_SIZE

public static final int REF_SIZE
The number of bytes a reference will have


INSTANCE_SIZE

public static final int INSTANCE_SIZE
The number of bytes a simple new Object without any fields will consume.


INT_SIZE

public static final int INT_SIZE
Number of bytes for an int

See Also:
Constant Field Values

LONG_SIZE

public static final int LONG_SIZE
Number of bytes for an int

See Also:
Constant Field Values

FLOAT_SIZE

public static final int FLOAT_SIZE
Number of bytes for a float

See Also:
Constant Field Values

DOUBLE_SIZE

public static final int DOUBLE_SIZE
Number of bytes for a float

See Also:
Constant Field Values
Constructor Detail

AllocatedHeapMemory

public AllocatedHeapMemory()
Method Detail

instanceAndReferenceSize

public static final int instanceAndReferenceSize(boolean asReference)
This will return the size of an instance of a new Object, if the asReference is true, the size of a reference will be added as well.

Parameters:
asReference -
Returns:
occupied bytes of a simple object, optional as a reference.

roundToMem

public static final long roundToMem(long currentSize)
The JVM allocates 8 bytes at a time..

Parameters:
currentSize - of the object
Returns:
the next module 8 value.

sizeOfString

public static long sizeOfString(String s,
                                boolean asReference,
                                boolean internalised)
The approximate size of the given String Object in bytes.

Parameters:
s - to check
asReference - true if the String is a reference inside another class (if the size of a reference should be added).
internalised - the resulting string will not be internalised, for example if a StringBuilder is used.
Returns:
the approximate size of a String Object in bytes

sizeOfObjectArray

public static long sizeOfObjectArray(Object[] o,
                                     boolean asReference)
Parameters:
o -
asReference - true if the array is a reference inside another class (if the size of a reference should be added).
Returns:
The size of the actual array object, not the objects in them.

sizeOfFloatArray

public static long sizeOfFloatArray(float[] o,
                                    boolean asReference)
Parameters:
o -
asReference - true if the array is a reference inside another class (if the size of a reference should be added).
Returns:
The size of the actual array object.

sizeOfDoubleArray

public static long sizeOfDoubleArray(double[] o,
                                     boolean asReference)
Parameters:
o -
asReference - true if the array is a reference inside another class (if the size of a reference should be added).
Returns:
The size of the actual array object

sizeOfByteArray

public static long sizeOfByteArray(byte[] o,
                                   boolean asReference)
Parameters:
o -
asReference - true if the array is a reference inside another class (if the size of a reference should be added).
Returns:
The size of the actual array object

sizeOfIntArray

public static long sizeOfIntArray(int[] o,
                                  boolean asReference)
Parameters:
o -
asReference - true if the array is a reference inside another class (if the size of a reference should be added).
Returns:
The size of the actual array object

sizeOfLongArray

public static long sizeOfLongArray(int[] o,
                                   boolean asReference)
Parameters:
o -
asReference - true if the array is a reference inside another class (if the size of a reference should be added).
Returns:
The size of the actual array object

sizeOfList

public static long sizeOfList(List<?> l,
                              boolean asReference)
The size of the Objects referenced in the list are not accounted for.

Parameters:
l - get the bytes for.
asReference - true if the list is a reference inside another class (if the size of a reference should be added)
Returns:
the size of bytes of the given list.

sizeOfBuffer

public static long sizeOfBuffer(Buffer b,
                                boolean asReference)
Parameters:
b -
asReference - true if the buffer is a reference inside another class (if the size of a reference should be added)
Returns:
the size of the given buffer.


Copyright © 2011. All Rights Reserved.