public class CachedBufferAllocator extends java.lang.Object implements BufferAllocator
Modifier and Type | Field and Description |
---|---|
private java.util.Deque<byte[]> |
bufferQueue |
private int |
bufferSize |
private static BufferAllocatorFactory |
factory |
private static java.util.Map<java.lang.Integer,java.lang.ref.SoftReference<CachedBufferAllocator>> |
queueTable
Use SoftReference so that having this queueTable does not prevent the GC of CachedBufferAllocator instances
|
Constructor and Description |
---|
CachedBufferAllocator(int bufferSize) |
Modifier and Type | Method and Description |
---|---|
byte[] |
allocate(int size) |
static CachedBufferAllocator |
getAllocator(int bufferSize) |
static BufferAllocatorFactory |
getBufferAllocatorFactory() |
void |
release(byte[] buffer) |
static void |
setBufferAllocatorFactory(BufferAllocatorFactory factory) |
private static BufferAllocatorFactory factory
private static final java.util.Map<java.lang.Integer,java.lang.ref.SoftReference<CachedBufferAllocator>> queueTable
private final int bufferSize
private final java.util.Deque<byte[]> bufferQueue
public static void setBufferAllocatorFactory(BufferAllocatorFactory factory)
public static BufferAllocatorFactory getBufferAllocatorFactory()
public static CachedBufferAllocator getAllocator(int bufferSize)
public byte[] allocate(int size)
allocate
in interface BufferAllocator
public void release(byte[] buffer)
release
in interface BufferAllocator