Class OByteBufferPool

java.lang.Object
com.orientechnologies.common.directmemory.OByteBufferPool
All Implemented Interfaces:
OByteBufferPoolMXBean

public final class OByteBufferPool extends Object implements OByteBufferPoolMXBean
Object of this class works at the same time as factory for DirectByteBuffer objects and pool for DirectByteBuffer objects which were used and now are free to be reused by other parts of the code. All DirectByteBuffer objects have the same size which is specified in objects constructor as "page size".
See Also:
  • Constructor Details

    • OByteBufferPool

      public OByteBufferPool(int pageSize)
      Parameters:
      pageSize - Size of single page (instance of DirectByteBuffer) returned by pool.
    • OByteBufferPool

      public OByteBufferPool(int pageSize, ODirectMemoryAllocator allocator, int poolSize)
      Parameters:
      allocator - Direct memory allocator to use.
      pageSize - Size of single page (instance of DirectByteBuffer) returned by pool.
      poolSize - Size of the page pool
  • Method Details

    • instance

      public static OByteBufferPool instance(OContextConfiguration contextConfiguration)
      Returns:
      Singleton instance
    • acquireDirect

      public final OPointer acquireDirect(boolean clear, MemTrace intention)
      Acquires direct memory buffer with native byte order. If there is free (already released) direct memory page we reuse it, otherwise new memory chunk is allocated from direct memory.
      Parameters:
      clear - Whether returned buffer should be filled with zeros before return.
      intention - Why this memory is allocated. This parameter is used for memory profiling.
      Returns:
      Direct memory buffer instance.
    • release

      public final void release(OPointer pointer)
      Put buffer which is not used any more back to the pool or frees direct memory if pool is full.
      Parameters:
      pointer - Not used instance of buffer.
      See Also:
    • getPoolSize

      public final int getPoolSize()
      Specified by:
      getPoolSize in interface OByteBufferPoolMXBean
      Returns:
      Current size of the memory pool
    • checkMemoryLeaks

      public void checkMemoryLeaks()
      Checks whether there are not released buffers in the pool
    • clear

      public void clear()
      Clears pool and dealocates memory.