Package org.xerial.snappy.pool
Class CachingBufferPool
- java.lang.Object
-
- org.xerial.snappy.pool.CachingBufferPool
-
- All Implemented Interfaces:
BufferPool
public final class CachingBufferPool extends java.lang.Object implements BufferPool
ABufferPoolimplementation which caches values at fixed sizes.Pooled instances are held as
SoftReferenceto allow GC if necessary.The current fixed sizes are calculated as follows:
- Values < 4KB return 4KB
- 4KB - 32KB to 2KB
- 32KB - 512KB to 16KB
- 512KB - 2MB to 128KB
- 2MB - 16MB to 512KB
- 16MB - 128MB to 4MB
- 128MB - 512MB to 16MB
- 512MB - 1.5 GB to 128MB
- Values > 1.5GB return
Integer.MAX_VALUE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]allocateArray(int size)Returns abyte[]of size or greater length.java.nio.ByteBufferallocateDirect(int size)Returns adirect ByteBufferof size or greatercapacity.static BufferPoolgetInstance()Returns instance ofCachingBufferPoolfor using cached buffers.voidreleaseArray(byte[] buffer)Returns instance to pool for potential future reuse.voidreleaseDirect(java.nio.ByteBuffer buffer)Returns instance to pool for potential future reuse.java.lang.StringtoString()
-
-
-
Method Detail
-
getInstance
public static BufferPool getInstance()
Returns instance ofCachingBufferPoolfor using cached buffers.- Returns:
- instance of
CachingBufferPoolfor using cached buffers.
-
allocateArray
public byte[] allocateArray(int size)
Returns abyte[]of size or greater length.- Specified by:
allocateArrayin interfaceBufferPool- Parameters:
size- The minimum size array required. Must be>= 0.- Returns:
- A
byte[]with length of at least size. - See Also:
BufferPool.releaseArray(byte[])
-
releaseArray
public void releaseArray(byte[] buffer)
Returns instance to pool for potential future reuse.Must not be returned more than 1 time. Must not be used by caller after return.
- Specified by:
releaseArrayin interfaceBufferPool- Parameters:
buffer- Instance to return to pool. Must not benull. Must not be returned more than 1 time. Must not be used by caller after return.
-
allocateDirect
public java.nio.ByteBuffer allocateDirect(int size)
Returns adirect ByteBufferof size or greatercapacity.- Specified by:
allocateDirectin interfaceBufferPool- Parameters:
size- The minimum size buffer required. Must be>= 0.- Returns:
- A
ByteBufferof size or greatercapacity. - See Also:
BufferPool.releaseDirect(ByteBuffer),ByteBuffer.allocateDirect(int)
-
releaseDirect
public void releaseDirect(java.nio.ByteBuffer buffer)
Returns instance to pool for potential future reuse.Must not be returned more than 1 time. Must not be used by caller after return.
- Specified by:
releaseDirectin interfaceBufferPool- Parameters:
buffer- Instance to return to pool. Must not benull. Must not be returned more than 1 time. Must not be used by caller after return.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-