public final class RecyclingByteBlockAllocator extends ByteBlockPool.Allocator
ByteBlockPool.Allocator
implementation that recycles unused byte
blocks in a buffer and reuses them in subsequent calls to
getByteBlock()
.
Note: This class is not thread-safe
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFERED_BLOCKS |
blockSize
Constructor and Description |
---|
RecyclingByteBlockAllocator()
Creates a new
RecyclingByteBlockAllocator with a block size of
ByteBlockPool.BYTE_BLOCK_SIZE , upper buffered docs limit of
DEFAULT_BUFFERED_BLOCKS (64). |
RecyclingByteBlockAllocator(int blockSize,
int maxBufferedBlocks)
Creates a new
RecyclingByteBlockAllocator . |
RecyclingByteBlockAllocator(int blockSize,
int maxBufferedBlocks,
Counter bytesUsed)
Creates a new
RecyclingByteBlockAllocator |
Modifier and Type | Method and Description |
---|---|
long |
bytesUsed() |
int |
freeBlocks(int num)
Removes the given number of byte blocks from the buffer if possible.
|
byte[] |
getByteBlock() |
int |
maxBufferedBlocks() |
int |
numBufferedBlocks() |
void |
recycleByteBlocks(byte[][] blocks,
int start,
int end) |
recycleByteBlocks
public static final int DEFAULT_BUFFERED_BLOCKS
public RecyclingByteBlockAllocator(int blockSize, int maxBufferedBlocks, Counter bytesUsed)
RecyclingByteBlockAllocator
blockSize
- the block size in bytesmaxBufferedBlocks
- maximum number of buffered byte blockbytesUsed
- Counter
reference counting internally allocated bytespublic RecyclingByteBlockAllocator(int blockSize, int maxBufferedBlocks)
RecyclingByteBlockAllocator
.blockSize
- the block size in bytesmaxBufferedBlocks
- maximum number of buffered byte blockpublic RecyclingByteBlockAllocator()
RecyclingByteBlockAllocator
with a block size of
ByteBlockPool.BYTE_BLOCK_SIZE
, upper buffered docs limit of
DEFAULT_BUFFERED_BLOCKS
(64).public byte[] getByteBlock()
getByteBlock
in class ByteBlockPool.Allocator
public void recycleByteBlocks(byte[][] blocks, int start, int end)
recycleByteBlocks
in class ByteBlockPool.Allocator
public int numBufferedBlocks()
public long bytesUsed()
ByteBlockPool.Allocator
public int maxBufferedBlocks()
public int freeBlocks(int num)
num
- the number of byte blocks to removeCopyright © 2000-2021 Apache Software Foundation. All Rights Reserved.