public abstract class ReusingByteBufferAllocator extends Object implements ByteBufferAllocator, AutoCloseable
ByteBufferAllocator implementation that keeps one ByteBuffer object and reuses it at the
next allocate(int) call. The close() shall be called when this allocator is not needed anymore to
really release the one buffer.| Modifier and Type | Method and Description |
|---|---|
ByteBuffer |
allocate(int size) |
void |
close() |
ByteBufferReleaser |
getReleaser()
A convenience method to get a
ByteBufferReleaser instance already created for this allocator. |
boolean |
isDirect()
Indicates if this allocator will produce ByteBuffers backed by direct memory.
|
void |
release(ByteBuffer b)
For RefCounted implementations using direct memory, the release method
needs to be called to free references to the allocated memory.
|
static ReusingByteBufferAllocator |
strict(ByteBufferAllocator allocator)
Creates a new strict
ReusingByteBufferAllocator object with the specified "parent" allocator to be used for
allocating/releasing the one buffer. |
static ReusingByteBufferAllocator |
unsafe(ByteBufferAllocator allocator)
Creates a new unsafe
ReusingByteBufferAllocator object with the specified "parent" allocator to be used for
allocating/releasing the one buffer. |
public static ReusingByteBufferAllocator strict(ByteBufferAllocator allocator)
ReusingByteBufferAllocator object with the specified "parent" allocator to be used for
allocating/releasing the one buffer.
Strict means it is enforced that release(ByteBuffer) is invoked before a new allocate(int) can be
called.
allocator - the allocator to be used for allocating/releasing the one bufferReusingByteBufferAllocator objectpublic static ReusingByteBufferAllocator unsafe(ByteBufferAllocator allocator)
ReusingByteBufferAllocator object with the specified "parent" allocator to be used for
allocating/releasing the one buffer.
Unsafe means it is not enforced that release(ByteBuffer) is invoked before a new allocate(int)
can be called, i.e. no exceptions will be thrown at allocate(int).
allocator - the allocator to be used for allocating/releasing the one bufferReusingByteBufferAllocator objectpublic ByteBufferReleaser getReleaser()
ByteBufferReleaser instance already created for this allocator.public ByteBuffer allocate(int size)
allocate in interface ByteBufferAllocatorIllegalStateException - if strict and the one buffer was not released yetstrict(ByteBufferAllocator),
unsafe(ByteBufferAllocator)public void release(ByteBuffer b)
release in interface ByteBufferAllocatorb - a ByteBufferIllegalStateException - if the one buffer has already been released or never allocatedIllegalArgumentException - if the specified buffer is not the one allocated by this allocatorpublic boolean isDirect()
ByteBufferAllocatorisDirect in interface ByteBufferAllocatorpublic void close()
close in interface AutoCloseableCopyright © 2023 The Apache Software Foundation. All rights reserved.