Interface ByteBufferPool
- All Known Implementing Classes:
 ArrayByteBufferPool, ArrayByteBufferPool.Quadratic, ArrayByteBufferPool.Tracking, ArrayByteBufferPool.WithBucketCapacities, ByteBufferPool.NonPooling, ByteBufferPool.Sized, ByteBufferPool.Wrapper
A pool for RetainableByteBuffer instances.
RetainableByteBuffer that are acquired
must be released by calling Retainable.release()
otherwise the memory they hold will be leaked.
API NOTE
This interface does not have a symmetric release(RetainableByteBuffer)
method, because it will be confusing to use due to the fact that the acquired instance
is-a Retainable.
Imagine this (hypothetical) code sequence:
RetainableByteBuffer buffer = pool.acquire(size, direct);
buffer.retain();
pool.release(buffer);
The hypothetical call to release(RetainableByteBuffer) would appear to
release the buffer to the pool, but in fact the buffer is retained one more time
(and therefore still in use) and not really released to the pool.
For this reason there is no release(RetainableByteBuffer) method.
Therefore, in order to track acquire/release counts both the pool and the
buffer returned by acquire(int, boolean) must be wrapped, see
RetainableByteBuffer.Wrapper
- 
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classDeprecated, for removal: This API element is subject to removal in a future version.static classAByteBufferPoolthat does not pool itsRetainableByteBuffers.static classA ByteBufferPool with an additional no-argsByteBufferPool.Sized.acquire()method to obtain a buffer of a preconfigured specific size and type.static classA wrapper forByteBufferPoolinstances. - 
Field Summary
Fields - 
Method Summary
Modifier and TypeMethodDescriptionacquire(int size, boolean direct) Acquires aRetainableByteBufferfrom this pool.voidclear()Removes allnon-retainedpooled instances from this pool. 
- 
Field Details
- 
NON_POOLING
 - 
SIZED_NON_POOLING
 
 - 
 - 
Method Details
- 
acquire
Acquires a
RetainableByteBufferfrom this pool.- Parameters:
 size- The size of the buffer. The returned buffer will have at least this capacity.direct- true if a direct memory buffer is needed, false otherwise.- Returns:
 - a 
RetainableByteBufferwith position and limit set to 0. 
 - 
clear
void clear()Removes all
non-retainedpooled instances from this pool. 
 - 
 
RetainableByteBuffer.DynamicCapacity