Class ByteBuffAllocator

java.lang.Object
org.apache.hadoop.hbase.io.ByteBuffAllocator
Direct Known Subclasses:
DeallocateRewriteByteBuffAllocator

@Private public class ByteBuffAllocator extends Object
ByteBuffAllocator is a nio ByteBuffer pool. It returns ByteBuffs which are wrappers of offheap ByteBuffer usually. If we are sure that the returned ByteBuffs have reached the end of their life cycle, we must call ByteBuff.release() to return buffers to the pool otherwise the pool will leak. If the desired memory size is larger than what the ByteBufferPool has available, we'll downgrade to allocate ByteBuffers from the heap. Increase the ByteBufferPool size if detect this case.

For better memory/pool utilization, there is a lower bound named minSizeForReservoirUse in this allocator, and if the desired size is less than minSizeForReservoirUse, the allocator will just allocate the ByteBuffer from heap and let the JVM manage memory, because it better to not waste pool slots allocating a single fixed-size ByteBuffer for a small object.

This pool can be used anywhere it makes sense managing memory. Currently used at least by RPC.