All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xerial.snappy.pool.QuiescentBufferPool Maven / Gradle / Ivy

package org.xerial.snappy.pool;

import java.nio.ByteBuffer;

/**
 * A {@link BufferPool} implementation which does no pooling. New instances will be created for each call to allocate.
 * @author Brett Okken
 */
public final class QuiescentBufferPool implements BufferPool {

    private static final QuiescentBufferPool INSTANCE = new QuiescentBufferPool();

    private QuiescentBufferPool() {
    }

    /**
     * @return Instance of {@link BufferPool} which does no caching/reuse of instances.
     */
    public static BufferPool getInstance() {
        return INSTANCE;
    }
    
    /**
     * Creates a new {@code byte[]} of size.
     */
    @Override
    public byte[] allocateArray(int size) {
        return new byte[size];
    }

    /**
     * Does nothing.
     */
    @Override
    public void releaseArray(byte[] buffer) {
    }

    /**
     * {@link ByteBuffer#allocateDirect(int) Allocates} a direct {@link ByteBuffer} of size.
     */
    @Override
    public ByteBuffer allocateDirect(int size) {
        return ByteBuffer.allocateDirect(size);
    }

    /**
     * Aggressively releases native resources associated with buffer.
     */
    @Override
    public void releaseDirect(ByteBuffer buffer) {
        assert buffer != null && buffer.isDirect();
        DirectByteBuffers.releaseDirectByteBuffer(buffer);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy