public class StaticBuffers
extends java.lang.Object
SoftReference so buffers can be freed when they are not needed
anymore.BufferRecycler| Modifier and Type | Class and Description |
|---|---|
static class |
StaticBuffers.Key
Possible buffer keys
|
| Modifier and Type | Field and Description |
|---|---|
protected java.nio.ByteBuffer[] |
_byteBuffers
Maps of already allocated re-usable buffers
|
protected java.nio.CharBuffer[] |
_charBuffers |
protected static java.lang.ThreadLocal<java.lang.ref.SoftReference<StaticBuffers>> |
_instance
A thread-local soft reference to the singleton instance of this class
|
static int |
GLOBAL_MIN_SIZE
All buffers have a minimum size of 64 kb
|
| Modifier | Constructor and Description |
|---|---|
protected |
StaticBuffers()
Hidden constructor
|
| Modifier and Type | Method and Description |
|---|---|
java.nio.ByteBuffer |
byteBuffer(StaticBuffers.Key key,
int minSize)
Creates or re-uses a
ByteBuffer that has a minimum size. |
java.nio.CharBuffer |
charBuffer(StaticBuffers.Key key,
int minSize)
Creates or re-uses a
CharBuffer that has a minimum size. |
static StaticBuffers |
getInstance() |
void |
releaseByteBuffer(StaticBuffers.Key key,
java.nio.ByteBuffer buf)
Marks a buffer a being re-usable.
|
void |
releaseCharBuffer(StaticBuffers.Key key,
java.nio.CharBuffer buf)
Marks a buffer a being re-usable.
|
public static final int GLOBAL_MIN_SIZE
protected static final java.lang.ThreadLocal<java.lang.ref.SoftReference<StaticBuffers>> _instance
protected java.nio.ByteBuffer[] _byteBuffers
protected java.nio.CharBuffer[] _charBuffers
public static StaticBuffers getInstance()
public java.nio.CharBuffer charBuffer(StaticBuffers.Key key, int minSize)
CharBuffer that has a minimum size. Calling
this method multiple times with the same key will always return the
same buffer, as long as it has the minimum size and is marked to be
re-used. Buffers that are allowed to be re-used should be released using
releaseCharBuffer(Key, CharBuffer).key - the buffer's identifierminSize - the minimum sizeCharBuffer instancebyteBuffer(Key, int)public void releaseCharBuffer(StaticBuffers.Key key, java.nio.CharBuffer buf)
key - the buffer's keybuf - the bufferreleaseByteBuffer(Key, ByteBuffer)public java.nio.ByteBuffer byteBuffer(StaticBuffers.Key key, int minSize)
ByteBuffer that has a minimum size. Calling
this method multiple times with the same key will always return the
same buffer, as long as it has the minimum size and is marked to be
re-used. Buffers that are allowed to be re-used should be released using
releaseByteBuffer(Key, ByteBuffer).key - the buffer's identifierminSize - the minimum sizeByteBuffer instancecharBuffer(Key, int)public void releaseByteBuffer(StaticBuffers.Key key, java.nio.ByteBuffer buf)
key - the buffer's keybuf - the bufferreleaseCharBuffer(Key, CharBuffer)