Interface ByteBufferPool


  • public interface ByteBufferPool
    Object Pool that allows to borrow and release ByteBuffers according to a specific type (direct/heap).
    The suggested usage pattern is:
    
        ByteBuffer buffer = pool.borrow(size);
        //...using buffer...
        pool.release(buffer);
     
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.nio.ByteBuffer borrow​(int size, boolean zeroed)
      It returns a ByteBuffer with Buffer.capacity() >= size.
      The buffer is zeroed until size if zeroed=true, with Buffer.position()=0 and Buffer.limit()=size.
      void release​(java.nio.ByteBuffer buffer)
      It pools or free buffer that cannot be used anymore.
      If buffer is of a type different from the one that the pool can borrow, it will ignore it.
      static ByteBufferPool threadLocal​(boolean direct)
      Factory method that creates a thread-local pool of capacity 1 of ByteBuffers of the specified type (direct/heap).
    • Method Detail

      • borrow

        java.nio.ByteBuffer borrow​(int size,
                                   boolean zeroed)
        It returns a ByteBuffer with Buffer.capacity() >= size.
        The buffer is zeroed until size if zeroed=true, with Buffer.position()=0 and Buffer.limit()=size.
      • release

        void release​(java.nio.ByteBuffer buffer)
        It pools or free buffer that cannot be used anymore.
        If buffer is of a type different from the one that the pool can borrow, it will ignore it.
      • threadLocal

        static ByteBufferPool threadLocal​(boolean direct)
        Factory method that creates a thread-local pool of capacity 1 of ByteBuffers of the specified type (direct/heap).