Interface ByteBufferPool

All Known Implementing Classes:
ArrayByteBufferPool, LeakTrackingByteBufferPool, LogarithmicArrayByteBufferPool, MappedByteBufferPool, MappedByteBufferPool.Tagged, NullByteBufferPool

public interface ByteBufferPool

A ByteBuffer pool.

Acquired buffers may be released but they do not need to; if they are released, they may be recycled and reused, otherwise they will be garbage collected as usual.

  • Method Details

    • acquire

      ByteBuffer acquire(int size, boolean direct)

      Requests a ByteBuffer of the given size.

      The returned buffer may have a bigger capacity than the size being requested.

      size - the size of the buffer
      direct - whether the buffer must be direct or not
      a buffer with at least the requested capacity, with position and limit set to 0.
      See Also:
    • release

      void release(ByteBuffer buffer)

      Returns a ByteBuffer, usually obtained with acquire(int, boolean) (but not necessarily), making it available for recycling and reuse.

      buffer - the buffer to return
      See Also:
    • remove

      default void remove(ByteBuffer buffer)

      Removes a ByteBuffer that was previously obtained with acquire(int, boolean).

      The buffer will not be available for further reuse.

      buffer - the buffer to remove
      See Also:
    • newByteBuffer

      default ByteBuffer newByteBuffer(int capacity, boolean direct)

      Creates a new ByteBuffer of the given capacity and the given directness.

      capacity - the ByteBuffer capacity
      direct - the ByteBuffer directness
      a newly allocated ByteBuffer
    • asRetainableByteBufferPool

      RetainableByteBufferPool asRetainableByteBufferPool()
      Get this pool as a RetainableByteBufferPool, which supports reference counting of the buffers and possibly a more efficient lookup mechanism based on the Pool class.
      This pool as a RetainableByteBufferPool. The same instance is always returned by multiple calls to this method.