Package org.xerial.snappy.buffer
Class CachedBufferAllocator
- java.lang.Object
-
- org.xerial.snappy.buffer.CachedBufferAllocator
-
- All Implemented Interfaces:
BufferAllocator
public class CachedBufferAllocator extends java.lang.Object implements BufferAllocator
Cached buffer
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Deque<byte[]>bufferQueueprivate intbufferSizeprivate static BufferAllocatorFactoryfactoryprivate static java.util.Map<java.lang.Integer,java.lang.ref.SoftReference<CachedBufferAllocator>>queueTableUse SoftReference so that having this queueTable does not prevent the GC of CachedBufferAllocator instances
-
Constructor Summary
Constructors Constructor Description CachedBufferAllocator(int bufferSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]allocate(int size)static CachedBufferAllocatorgetAllocator(int bufferSize)static BufferAllocatorFactorygetBufferAllocatorFactory()voidrelease(byte[] buffer)static voidsetBufferAllocatorFactory(BufferAllocatorFactory factory)
-
-
-
Field Detail
-
factory
private static BufferAllocatorFactory factory
-
queueTable
private static final java.util.Map<java.lang.Integer,java.lang.ref.SoftReference<CachedBufferAllocator>> queueTable
Use SoftReference so that having this queueTable does not prevent the GC of CachedBufferAllocator instances
-
bufferSize
private final int bufferSize
-
bufferQueue
private final java.util.Deque<byte[]> bufferQueue
-
-
Method Detail
-
setBufferAllocatorFactory
public static void setBufferAllocatorFactory(BufferAllocatorFactory factory)
-
getBufferAllocatorFactory
public static BufferAllocatorFactory getBufferAllocatorFactory()
-
getAllocator
public static CachedBufferAllocator getAllocator(int bufferSize)
-
allocate
public byte[] allocate(int size)
- Specified by:
allocatein interfaceBufferAllocator
-
release
public void release(byte[] buffer)
- Specified by:
releasein interfaceBufferAllocator
-
-