org.apache.directmemory.memory.allocator
Class FixedSizeByteBufferAllocatorImpl
java.lang.Object
org.apache.directmemory.memory.allocator.AbstractByteBufferAllocator
org.apache.directmemory.memory.allocator.FixedSizeByteBufferAllocatorImpl
- All Implemented Interfaces:
- Closeable, ByteBufferAllocator
public class FixedSizeByteBufferAllocatorImpl
- extends AbstractByteBufferAllocator
ByteBufferAllocator implementation that instantiate ByteBuffers of fixed size, called slices.
- Since:
- 0.6
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FixedSizeByteBufferAllocatorImpl
public FixedSizeByteBufferAllocatorImpl(int number,
int totalSize,
int sliceSize,
int numberOfSegments)
- Constructor.
- Parameters:
number - : internal identifier of the allocatortotalSize - : the internal buffersliceSize - : arbitrary number of the buffer.numberOfSegments - : number of parent ByteBuffer to allocate.
init
protected void init(int numberOfSegments)
findFreeBuffer
protected ByteBuffer findFreeBuffer(int capacity)
free
public void free(ByteBuffer byteBuffer)
- Description copied from interface:
ByteBufferAllocator
- Returns the given
ByteBuffer making it available for a future usage. Returning twice a ByteBuffer won't throw an exception.
- Parameters:
byteBuffer - : the ByteBuffer to return
allocate
public ByteBuffer allocate(int size)
- Description copied from interface:
ByteBufferAllocator
- Allocates and returns a
ByteBuffer with Buffer.limit() set to the given size.
When the allocation fails, it returns either null or throws an BufferOverflowException, depending on the implementation.
- Parameters:
size - : the size in byte to allocate
- Returns:
- a
ByteBuffer of the given size, or either return null or throw an BufferOverflowException when the allocation fails.
getSliceSize
public int getSliceSize()
clear
public void clear()
- Description copied from interface:
ByteBufferAllocator
- Clear all allocated
ByteBuffer, resulting in a empty and ready to deserve ByteBufferAllocator
getCapacity
public int getCapacity()
- Returns:
- the internal total size that can be allocated
close
public void close()
Copyright © 2011-2012 The Apache Software Foundation. All Rights Reserved.