1 package org.xerial.snappy.pool; 2 3 import java.nio.ByteBuffer; 4 5 /** 6 * A {@link BufferPool} implementation which does no pooling. New instances will be created for each call to allocate. 7 * @author Brett Okken 8 */ 9 public final class QuiescentBufferPool implements BufferPool { 10 11 private static final QuiescentBufferPool INSTANCE = new QuiescentBufferPool(); 12 QuiescentBufferPool()13 private QuiescentBufferPool() { 14 } 15 16 /** 17 * @return Instance of {@link BufferPool} which does no caching/reuse of instances. 18 */ getInstance()19 public static BufferPool getInstance() { 20 return INSTANCE; 21 } 22 23 /** 24 * Creates a new {@code byte[]} of <i>size</i>. 25 */ 26 @Override allocateArray(int size)27 public byte[] allocateArray(int size) { 28 return new byte[size]; 29 } 30 31 /** 32 * Does nothing. 33 */ 34 @Override releaseArray(byte[] buffer)35 public void releaseArray(byte[] buffer) { 36 } 37 38 /** 39 * {@link ByteBuffer#allocateDirect(int) Allocates} a direct {@link ByteBuffer} of <i>size</i>. 40 */ 41 @Override allocateDirect(int size)42 public ByteBuffer allocateDirect(int size) { 43 return ByteBuffer.allocateDirect(size); 44 } 45 46 /** 47 * Aggressively releases native resources associated with <i>buffer</i>. 48 */ 49 @Override releaseDirect(ByteBuffer buffer)50 public void releaseDirect(ByteBuffer buffer) { 51 assert buffer != null && buffer.isDirect(); 52 DirectByteBuffers.releaseDirectByteBuffer(buffer); 53 } 54 55 } 56