Top Description Inners Fields Constructors Methods
com.jogamp.common.nio

public Class CachedBufferFactory

extends Object
Class Inheritance
Known Direct Subclasses
com.jogamp.common.nio.CachedBufferFactory.SynchronizedCachedBufferFactory
Imports
java.nio.ByteBuffer, .CharBuffer, .DoubleBuffer, .FloatBuffer, .IntBuffer, .LongBuffer, .ShortBuffer

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final int
private ByteBuffer
public static final int
DEFAULT_ALLOCATION_SIZE

default size for internal buffer allocation.

Constructor Summary

AccessConstructor and Description
private
private
CachedBufferFactory(final int initialSize, final int allocationSize)

Method Summary

Modifier and TypeMethod and Description
private void

Returns:

true if buffer cannot grow, otherwise false
checkIfFixed
()

public static CachedBufferFactory
create()

Creates a factory with initial size and allocation size set to DEFAULT_ALLOCATION_SIZE.

public static CachedBufferFactory
create(final int initialSize)

Creates a factory with the specified initial size.

public static CachedBufferFactory
create(final int initialSize, final boolean
Creates a fixed size factory which will handle overflows (initial size) with RuntimeExceptions.
fixed
)

Creates a factory with the specified initial size.

public static CachedBufferFactory
create(final int initialSize, final int allocationSize)

Creates a factory with the specified initial size and allocation size.

public static CachedBufferFactory
createSynchronized()

Synchronized version of create().

public static CachedBufferFactory
createSynchronized(final int initialSize)

Synchronized version of create(int).

public static CachedBufferFactory
createSynchronized(final int initialSize, final boolean fixed)

Synchronized version of create(int, boolean).

public static CachedBufferFactory
createSynchronized(final int initialSize, final int allocationSize)

Synchronized version of create(int, int).

public void
public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
getAllocationSize()

Returns the allocation size used to create new internal buffers.

public boolean
isFixed()

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

public ByteBuffer
newDirectByteBuffer(final int size)

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

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

public ByteBuffer
newDirectByteBuffer(final byte[] values)

public CharBuffer
newDirectCharBuffer(final int numElements)

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

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

public CharBuffer
newDirectCharBuffer(final char[] values)

public DoubleBuffer
newDirectDoubleBuffer(final int numElements)

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

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

public DoubleBuffer
newDirectDoubleBuffer(final double[] values)

public FloatBuffer
newDirectFloatBuffer(final int numElements)

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

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

public FloatBuffer
newDirectFloatBuffer(final float[] values)

public IntBuffer
newDirectIntBuffer(final int numElements)

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

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

public IntBuffer
newDirectIntBuffer(final int[] values)

public LongBuffer
newDirectLongBuffer(final int numElements)

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

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

public LongBuffer
newDirectLongBuffer(final long[] values)

public ShortBuffer
newDirectShortBuffer(final int numElements)

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

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

public ShortBuffer
newDirectShortBuffer(final short[] values)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ALLOCATION_SIZEback to summary
private final int ALLOCATION_SIZE
currentBufferback to summary
private ByteBuffer currentBuffer
DEFAULT_ALLOCATION_SIZEback to summary
public static final int DEFAULT_ALLOCATION_SIZE

default size for internal buffer allocation.

Constructor Detail

CachedBufferFactoryback to summary
private CachedBufferFactory()
CachedBufferFactoryback to summary
private CachedBufferFactory(final int initialSize, final int allocationSize)

Method Detail

checkIfFixedback to summary
private void checkIfFixed()
Returns:void

true if buffer cannot grow, otherwise false

createback to summary
public static CachedBufferFactory create()

Creates a factory with initial size and allocation size set to DEFAULT_ALLOCATION_SIZE.

createback to summary
public static CachedBufferFactory create(final int initialSize)

Creates a factory with the specified initial size. The allocation size is set to DEFAULT_ALLOCATION_SIZE.

createback to summary
public static CachedBufferFactory create(final int initialSize, final boolean fixed)

Creates a factory with the specified initial size. The allocation size is set to DEFAULT_ALLOCATION_SIZE.

Parameters
fixed:boolean

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

createback to summary
public static CachedBufferFactory create(final int initialSize, final int allocationSize)

Creates a factory with the specified initial size and allocation size.

createSynchronizedback to summary
public static CachedBufferFactory createSynchronized()

Synchronized version of create().

createSynchronizedback to summary
public static CachedBufferFactory createSynchronized(final int initialSize)

Synchronized version of create(int).

createSynchronizedback to summary
public static CachedBufferFactory createSynchronized(final int initialSize, final boolean fixed)

Synchronized version of create(int, boolean).

createSynchronizedback to summary
public static CachedBufferFactory createSynchronized(final int initialSize, final int allocationSize)

Synchronized version of create(int, int).

destroyback to summary
public void destroy()
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getAllocationSizeback to summary
public int getAllocationSize()

Returns the allocation size used to create new internal buffers. 0 means that the buffer will not grows, see isFixed().

isFixedback to summary
public boolean isFixed()

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

newDirectByteBufferback to summary
public ByteBuffer newDirectByteBuffer(final int size)
newDirectByteBufferback to summary
public ByteBuffer newDirectByteBuffer(final byte[] values, final int offset, final int lenght)
newDirectByteBufferback to summary
public ByteBuffer newDirectByteBuffer(final byte[] values, final int offset)
newDirectByteBufferback to summary
public ByteBuffer newDirectByteBuffer(final byte[] values)
newDirectCharBufferback to summary
public CharBuffer newDirectCharBuffer(final int numElements)
newDirectCharBufferback to summary
public CharBuffer newDirectCharBuffer(final char[] values, final int offset, final int lenght)
newDirectCharBufferback to summary
public CharBuffer newDirectCharBuffer(final char[] values, final int offset)
newDirectCharBufferback to summary
public CharBuffer newDirectCharBuffer(final char[] values)
newDirectDoubleBufferback to summary
public DoubleBuffer newDirectDoubleBuffer(final int numElements)
newDirectDoubleBufferback to summary
public DoubleBuffer newDirectDoubleBuffer(final double[] values, final int offset, final int lenght)
newDirectDoubleBufferback to summary
public DoubleBuffer newDirectDoubleBuffer(final double[] values, final int offset)
newDirectDoubleBufferback to summary
public DoubleBuffer newDirectDoubleBuffer(final double[] values)
newDirectFloatBufferback to summary
public FloatBuffer newDirectFloatBuffer(final int numElements)
newDirectFloatBufferback to summary
public FloatBuffer newDirectFloatBuffer(final float[] values, final int offset, final int lenght)
newDirectFloatBufferback to summary
public FloatBuffer newDirectFloatBuffer(final float[] values, final int offset)
newDirectFloatBufferback to summary
public FloatBuffer newDirectFloatBuffer(final float[] values)
newDirectIntBufferback to summary
public IntBuffer newDirectIntBuffer(final int numElements)
newDirectIntBufferback to summary
public IntBuffer newDirectIntBuffer(final int[] values, final int offset, final int lenght)
newDirectIntBufferback to summary
public IntBuffer newDirectIntBuffer(final int[] values, final int offset)
newDirectIntBufferback to summary
public IntBuffer newDirectIntBuffer(final int[] values)
newDirectLongBufferback to summary
public LongBuffer newDirectLongBuffer(final int numElements)
newDirectLongBufferback to summary
public LongBuffer newDirectLongBuffer(final long[] values, final int offset, final int lenght)
newDirectLongBufferback to summary
public LongBuffer newDirectLongBuffer(final long[] values, final int offset)
newDirectLongBufferback to summary
public LongBuffer newDirectLongBuffer(final long[] values)
newDirectShortBufferback to summary
public ShortBuffer newDirectShortBuffer(final int numElements)
newDirectShortBufferback to summary
public ShortBuffer newDirectShortBuffer(final short[] values, final int offset, final int lenght)
newDirectShortBufferback to summary
public ShortBuffer newDirectShortBuffer(final short[] values, final int offset)
newDirectShortBufferback to summary
public ShortBuffer newDirectShortBuffer(final short[] values)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.jogamp.common.nio back to summary

private Class CachedBufferFactory.SynchronizedCachedBufferFactory

extends CachedBufferFactory
Class Inheritance

Field Summary

Inherited from com.jogamp.common.nio.CachedBufferFactory:
DEFAULT_ALLOCATION_SIZE

Constructor Summary

AccessConstructor and Description
private
private
SynchronizedCachedBufferFactory(final int size, final int step)

Method Summary

Modifier and TypeMethod and Description
public synchronized ByteBuffer
Inherited from com.jogamp.common.nio.CachedBufferFactory:
createcreatecreatecreatecreateSynchronizedcreateSynchronizedcreateSynchronizedcreateSynchronizeddestroyequalsgetAllocationSizeisFixednewDirectByteBuffernewDirectByteBuffernewDirectByteBuffernewDirectCharBuffernewDirectCharBuffernewDirectCharBuffernewDirectCharBuffernewDirectDoubleBuffernewDirectDoubleBuffernewDirectDoubleBuffernewDirectDoubleBuffernewDirectFloatBuffernewDirectFloatBuffernewDirectFloatBuffernewDirectFloatBuffernewDirectIntBuffernewDirectIntBuffernewDirectIntBuffernewDirectIntBuffernewDirectLongBuffernewDirectLongBuffernewDirectLongBuffernewDirectLongBuffernewDirectShortBuffernewDirectShortBuffernewDirectShortBuffernewDirectShortBuffertoString

Constructor Detail

SynchronizedCachedBufferFactoryback to summary
private SynchronizedCachedBufferFactory()
SynchronizedCachedBufferFactoryback to summary
private SynchronizedCachedBufferFactory(final int size, final int step)

Method Detail

newDirectByteBufferback to summary
public synchronized ByteBuffer newDirectByteBuffer(final int size)

Overrides com.jogamp.common.nio.CachedBufferFactory.newDirectByteBuffer.

Annotations
@Override