com.jogamp.common.nio
Class CachedBufferFactory

java.lang.Object
  extended by com.jogamp.common.nio.CachedBufferFactory

public class CachedBufferFactory
extends Object

Buffer factory attempting to reduce buffer creation overhead. Direct ByteBuffers must be page aligned which increases creation overhead of small buffers significantly. This factory can be used as fixed size static or or dynamic allocating factory. The initial size and allocation size is configurable.

Fixed size factories may be used in systems with hard realtime requirements and/or predictable memory usage.

concurrency info:

Author:
Michael Bien

Field Summary
static int DEFAULT_ALLOCATION_SIZE
          default size for internal buffer allocation.
 
Method Summary
static CachedBufferFactory create()
          Creates a factory with initial size and allocation size set to DEFAULT_ALLOCATION_SIZE.
static CachedBufferFactory create(int initialSize)
          Creates a factory with the specified initial size.
static CachedBufferFactory create(int initialSize, boolean fixed)
          Creates a factory with the specified initial size.
static CachedBufferFactory create(int initialSize, int allocationSize)
          Creates a factory with the specified initial size and allocation size.
static CachedBufferFactory createSynchronized()
          Synchronized version of create().
static CachedBufferFactory createSynchronized(int initialSize)
          Synchronized version of create(int).
static CachedBufferFactory createSynchronized(int initialSize, boolean fixed)
          Synchronized version of create(int, boolean).
static CachedBufferFactory createSynchronized(int initialSize, int allocationSize)
          Synchronized version of create(int, int).
 boolean equals(Object obj)
           
 int getAllocationSize()
          Returns the allocation size used to create new internal buffers.
 boolean isFixed()
          Returns true only if this factory does not allow to allocate more buffers as limited by the initial size.
 ByteBuffer newDirectByteBuffer(byte[] values)
           
 ByteBuffer newDirectByteBuffer(byte[] values, int offset)
           
 ByteBuffer newDirectByteBuffer(byte[] values, int offset, int lenght)
           
 ByteBuffer newDirectByteBuffer(int size)
           
 CharBuffer newDirectCharBuffer(char[] values)
           
 CharBuffer newDirectCharBuffer(char[] values, int offset)
           
 CharBuffer newDirectCharBuffer(char[] values, int offset, int lenght)
           
 CharBuffer newDirectCharBuffer(int numElements)
           
 DoubleBuffer newDirectDoubleBuffer(double[] values)
           
 DoubleBuffer newDirectDoubleBuffer(double[] values, int offset)
           
 DoubleBuffer newDirectDoubleBuffer(double[] values, int offset, int lenght)
           
 DoubleBuffer newDirectDoubleBuffer(int numElements)
           
 FloatBuffer newDirectFloatBuffer(float[] values)
           
 FloatBuffer newDirectFloatBuffer(float[] values, int offset)
           
 FloatBuffer newDirectFloatBuffer(float[] values, int offset, int lenght)
           
 FloatBuffer newDirectFloatBuffer(int numElements)
           
 IntBuffer newDirectIntBuffer(int numElements)
           
 IntBuffer newDirectIntBuffer(int[] values)
           
 IntBuffer newDirectIntBuffer(int[] values, int offset)
           
 IntBuffer newDirectIntBuffer(int[] values, int offset, int lenght)
           
 LongBuffer newDirectLongBuffer(int numElements)
           
 LongBuffer newDirectLongBuffer(long[] values)
           
 LongBuffer newDirectLongBuffer(long[] values, int offset)
           
 LongBuffer newDirectLongBuffer(long[] values, int offset, int lenght)
           
 ShortBuffer newDirectShortBuffer(int numElements)
           
 ShortBuffer newDirectShortBuffer(short[] values)
           
 ShortBuffer newDirectShortBuffer(short[] values, int offset)
           
 ShortBuffer newDirectShortBuffer(short[] values, int offset, int lenght)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_ALLOCATION_SIZE

public static final int DEFAULT_ALLOCATION_SIZE
default size for internal buffer allocation.

See Also:
Constant Field Values
Method Detail

create

public static CachedBufferFactory create()
Creates a factory with initial size and allocation size set to DEFAULT_ALLOCATION_SIZE.


create

public static CachedBufferFactory create(int initialSize)
Creates a factory with the specified initial size. The allocation size is set to DEFAULT_ALLOCATION_SIZE.


create

public static CachedBufferFactory create(int initialSize,
                                         boolean fixed)
Creates a factory with the specified initial size. The allocation size is set to DEFAULT_ALLOCATION_SIZE.

Parameters:
fixed - Creates a fixed size factory which will handle overflows (initial size) with RuntimeExceptions.

create

public static CachedBufferFactory create(int initialSize,
                                         int allocationSize)
Creates a factory with the specified initial size and allocation size.


createSynchronized

public static CachedBufferFactory createSynchronized()
Synchronized version of create().


createSynchronized

public static CachedBufferFactory createSynchronized(int initialSize)
Synchronized version of create(int).


createSynchronized

public static CachedBufferFactory createSynchronized(int initialSize,
                                                     boolean fixed)
Synchronized version of create(int, boolean).


createSynchronized

public static CachedBufferFactory createSynchronized(int initialSize,
                                                     int allocationSize)
Synchronized version of create(int, int).


isFixed

public boolean isFixed()
Returns true only if this factory does not allow to allocate more buffers as limited by the initial size.


getAllocationSize

public int getAllocationSize()
Returns the allocation size used to create new internal buffers. This represents the initial size if isFixed() == true.


newDirectByteBuffer

public ByteBuffer newDirectByteBuffer(int size)

newDirectByteBuffer

public ByteBuffer newDirectByteBuffer(byte[] values,
                                      int offset,
                                      int lenght)

newDirectByteBuffer

public ByteBuffer newDirectByteBuffer(byte[] values,
                                      int offset)

newDirectByteBuffer

public ByteBuffer newDirectByteBuffer(byte[] values)

newDirectDoubleBuffer

public DoubleBuffer newDirectDoubleBuffer(int numElements)

newDirectDoubleBuffer

public DoubleBuffer newDirectDoubleBuffer(double[] values,
                                          int offset,
                                          int lenght)

newDirectDoubleBuffer

public DoubleBuffer newDirectDoubleBuffer(double[] values,
                                          int offset)

newDirectDoubleBuffer

public DoubleBuffer newDirectDoubleBuffer(double[] values)

newDirectFloatBuffer

public FloatBuffer newDirectFloatBuffer(int numElements)

newDirectFloatBuffer

public FloatBuffer newDirectFloatBuffer(float[] values,
                                        int offset,
                                        int lenght)

newDirectFloatBuffer

public FloatBuffer newDirectFloatBuffer(float[] values,
                                        int offset)

newDirectFloatBuffer

public FloatBuffer newDirectFloatBuffer(float[] values)

newDirectIntBuffer

public IntBuffer newDirectIntBuffer(int numElements)

newDirectIntBuffer

public IntBuffer newDirectIntBuffer(int[] values,
                                    int offset,
                                    int lenght)

newDirectIntBuffer

public IntBuffer newDirectIntBuffer(int[] values,
                                    int offset)

newDirectIntBuffer

public IntBuffer newDirectIntBuffer(int[] values)

newDirectLongBuffer

public LongBuffer newDirectLongBuffer(int numElements)

newDirectLongBuffer

public LongBuffer newDirectLongBuffer(long[] values,
                                      int offset,
                                      int lenght)

newDirectLongBuffer

public LongBuffer newDirectLongBuffer(long[] values,
                                      int offset)

newDirectLongBuffer

public LongBuffer newDirectLongBuffer(long[] values)

newDirectShortBuffer

public ShortBuffer newDirectShortBuffer(int numElements)

newDirectShortBuffer

public ShortBuffer newDirectShortBuffer(short[] values,
                                        int offset,
                                        int lenght)

newDirectShortBuffer

public ShortBuffer newDirectShortBuffer(short[] values,
                                        int offset)

newDirectShortBuffer

public ShortBuffer newDirectShortBuffer(short[] values)

newDirectCharBuffer

public CharBuffer newDirectCharBuffer(int numElements)

newDirectCharBuffer

public CharBuffer newDirectCharBuffer(char[] values,
                                      int offset,
                                      int lenght)

newDirectCharBuffer

public CharBuffer newDirectCharBuffer(char[] values,
                                      int offset)

newDirectCharBuffer

public CharBuffer newDirectCharBuffer(char[] values)

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object