public final class CachingBufferPool extends Object implements BufferPool
BufferPool
implementation which caches values at fixed sizes.
Pooled instances are held as SoftReference
to allow GC if necessary.
The current fixed sizes are calculated as follows:
Integer.MAX_VALUE
Modifier and Type | Method and Description |
---|---|
byte[] |
allocateArray(int size)
Returns a
byte[] of size or greater length. |
ByteBuffer |
allocateDirect(int size)
Returns a
direct ByteBuffer of size or
greater capacity . |
static BufferPool |
getInstance()
Returns instance of
CachingBufferPool for using cached buffers. |
void |
releaseArray(byte[] buffer)
Returns instance to pool for potential future reuse.
|
void |
releaseDirect(ByteBuffer buffer)
Returns instance to pool for potential future reuse.
|
String |
toString() |
public static BufferPool getInstance()
CachingBufferPool
for using cached buffers.CachingBufferPool
for using cached buffers.public byte[] allocateArray(int size)
byte[]
of size or greater length.allocateArray
in interface BufferPool
size
- The minimum size array required. Must be >= 0
.byte[]
with length of at least size.BufferPool.releaseArray(byte[])
public void releaseArray(byte[] buffer)
Must not be returned more than 1 time. Must not be used by caller after return.
releaseArray
in interface BufferPool
buffer
- Instance to return to pool. Must not be null
.
Must not be returned more than 1 time. Must not be used by caller after return.public ByteBuffer allocateDirect(int size)
direct ByteBuffer
of size or
greater capacity
.allocateDirect
in interface BufferPool
size
- The minimum size buffer required. Must be >= 0
.ByteBuffer
of size or greater capacity
.BufferPool.releaseDirect(ByteBuffer)
,
ByteBuffer.allocateDirect(int)
public void releaseDirect(ByteBuffer buffer)
Must not be returned more than 1 time. Must not be used by caller after return.
releaseDirect
in interface BufferPool
buffer
- Instance to return to pool. Must not be null
.
Must not be returned more than 1 time. Must not be used by caller after return.Copyright © 2024 xerial.org. All rights reserved.