|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.directmemory.memory.allocator.AbstractByteBufferAllocator
org.apache.directmemory.memory.allocator.MergingByteBufferAllocatorImpl
public class MergingByteBufferAllocatorImpl
ByteBufferAllocator implementation with ByteBuffer merging capabilities.
ByteBuffers are wrapped into an LinkedByteBuffer, and when a ByteBuffer is freed,
lookup is done to the neighbor to check if they are also free, in which case they are merged.
setMinSizeThreshold(int) gives the minimum buffer's size under which no splitting is done.
setSizeRatioThreshold(double) gives the size ratio (requested allocation / free buffer's size} under which no splitting is done
The free ByteBuffer are held into a NavigableMap with keys defining the size's range : 0 -> first key (included), first key -> second key (included), ...
Instead of keeping a list of ByteBuffers sorted by capacity, ByteBuffers in the same size's range are held in the same collection.
The size's range are computed by generateFreeSizesRange(Integer) and can be overridden.
| Field Summary |
|---|
| Fields inherited from class org.apache.directmemory.memory.allocator.AbstractByteBufferAllocator |
|---|
logger |
| Constructor Summary | |
|---|---|
MergingByteBufferAllocatorImpl(int number,
int totalSize)
Constructor. |
|
| Method Summary | |
|---|---|
ByteBuffer |
allocate(int size)
Allocates and returns a ByteBuffer with Buffer.limit() set to the given size. |
void |
clear()
Clear all allocated ByteBuffer, resulting in a empty and ready to deserve ByteBufferAllocator |
void |
close()
|
void |
free(ByteBuffer buffer)
Returns the given ByteBuffer making it available for a future usage. |
protected List<Integer> |
generateFreeSizesRange(Integer totalSize)
Generate free sizes' range. |
int |
getCapacity()
|
protected void |
init()
Initialization function. |
void |
setMinSizeThreshold(int minSizeThreshold)
|
void |
setReturnNullWhenBufferIsFull(boolean returnNullWhenBufferIsFull)
|
void |
setSizeRatioThreshold(double sizeRatioThreshold)
|
| Methods inherited from class org.apache.directmemory.memory.allocator.AbstractByteBufferAllocator |
|---|
getHash, getLogger, getNumber, isClosed, setClosed |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MergingByteBufferAllocatorImpl(int number,
int totalSize)
number - : the internal buffer identifiertotalSize - : total size of the parent buffer.| Method Detail |
|---|
protected void init()
Pointer mapping the whole buffer.
protected List<Integer> generateFreeSizesRange(Integer totalSize)
totalSize -
public void free(ByteBuffer buffer)
ByteBufferAllocatorByteBuffer making it available for a future usage. Returning twice a ByteBuffer won't throw an exception.
buffer - : the ByteBuffer to returnpublic ByteBuffer allocate(int size)
ByteBufferAllocatorByteBuffer with Buffer.limit() set to the given size.
When the allocation fails, it returns either null or throws an BufferOverflowException, depending on the implementation.
size - : the size in byte to allocate
ByteBuffer of the given size, or either return null or throw an BufferOverflowException when the allocation fails.public void clear()
ByteBufferAllocatorByteBuffer, resulting in a empty and ready to deserve ByteBufferAllocator
public void setSizeRatioThreshold(double sizeRatioThreshold)
public void setMinSizeThreshold(int minSizeThreshold)
public void setReturnNullWhenBufferIsFull(boolean returnNullWhenBufferIsFull)
public int getCapacity()
public void close()
throws IOException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||