public final class IntBlockPool
extends java.lang.Object
ByteBlockPool
Modifier and Type | Class and Description |
---|---|
static class |
IntBlockPool.Allocator
Abstract class for allocating and freeing int
blocks.
|
static class |
IntBlockPool.DirectAllocator
A simple
IntBlockPool.Allocator that never recycles. |
static class |
IntBlockPool.SliceReader
A
IntBlockPool.SliceReader that can read int slices written by a IntBlockPool.SliceWriter |
static class |
IntBlockPool.SliceWriter
A
IntBlockPool.SliceWriter that allows to write multiple integer slices into a given IntBlockPool . |
Modifier and Type | Field and Description |
---|---|
private IntBlockPool.Allocator |
allocator |
int[] |
buffer
Current head buffer
|
int[][] |
buffers
array of buffers currently used in the pool.
|
private int |
bufferUpto
index into the buffers array pointing to the current buffer used as the head
|
private static int |
FIRST_LEVEL_SIZE
The first level size for new slices
|
static int |
INT_BLOCK_MASK |
static int |
INT_BLOCK_SHIFT |
static int |
INT_BLOCK_SIZE |
int |
intOffset
Current head offset
|
int |
intUpto
Pointer to the current position in head buffer
|
private static int[] |
LEVEL_SIZE_ARRAY
An array holding the level sizes for int slices.
|
private static int[] |
NEXT_LEVEL_ARRAY
An array holding the offset into the
LEVEL_SIZE_ARRAY
to quickly navigate to the next slice level. |
Constructor and Description |
---|
IntBlockPool()
Creates a new
IntBlockPool with a default IntBlockPool.Allocator . |
IntBlockPool(IntBlockPool.Allocator allocator)
Creates a new
IntBlockPool with the given IntBlockPool.Allocator . |
Modifier and Type | Method and Description |
---|---|
private int |
allocSlice(int[] slice,
int sliceOffset)
Allocates a new slice from the given offset
|
private static boolean |
assertSliceBuffer(int[] buffer) |
private int |
newSlice(int size)
Creates a new int slice with the given starting size and returns the slices offset in the pool.
|
void |
nextBuffer()
Advances the pool to its next buffer.
|
void |
reset()
Resets the pool to its initial state reusing the first buffer.
|
void |
reset(boolean zeroFillBuffers,
boolean reuseFirst)
Expert: Resets the pool to its initial state reusing the first buffer.
|
public static final int INT_BLOCK_SHIFT
public static final int INT_BLOCK_SIZE
public static final int INT_BLOCK_MASK
public int[][] buffers
private int bufferUpto
public int intUpto
public int[] buffer
public int intOffset
private final IntBlockPool.Allocator allocator
private static final int[] NEXT_LEVEL_ARRAY
LEVEL_SIZE_ARRAY
to quickly navigate to the next slice level.private static final int[] LEVEL_SIZE_ARRAY
private static final int FIRST_LEVEL_SIZE
public IntBlockPool()
IntBlockPool
with a default IntBlockPool.Allocator
.nextBuffer()
public IntBlockPool(IntBlockPool.Allocator allocator)
IntBlockPool
with the given IntBlockPool.Allocator
.nextBuffer()
public void reset()
nextBuffer()
is not needed after reset.public void reset(boolean zeroFillBuffers, boolean reuseFirst)
zeroFillBuffers
- if true
the buffers are filled with 0.
This should be set to true
if this pool is used with
IntBlockPool.SliceWriter
.reuseFirst
- if true
the first buffer will be reused and calling
nextBuffer()
is not needed after reset iff the
block pool was used before ie. nextBuffer()
was called before.public void nextBuffer()
reset()
call will advance the pool to
its first buffer immediately.private int newSlice(int size)
IntBlockPool.SliceReader
private static final boolean assertSliceBuffer(int[] buffer)
private int allocSlice(int[] slice, int sliceOffset)