| Constructor and Description |
|---|
DefaultAllocator(int individualAllocationSize)
Constructs an initially empty pool.
|
DefaultAllocator(int individualAllocationSize,
int initialAllocationCount)
Constructs a pool with some
Allocations created up front. |
| Modifier and Type | Method and Description |
|---|---|
Allocation |
allocate()
Obtain an
Allocation. |
void |
blockWhileTotalBytesAllocatedExceeds(int limit)
Blocks execution until the number of bytes allocated is not greater than the limit, or the
thread is interrupted.
|
int |
getIndividualAllocationLength()
Returns the length of each individual
Allocation. |
int |
getTotalBytesAllocated()
Returns the total number of bytes currently allocated.
|
void |
release(Allocation allocation)
Return an
Allocation. |
void |
release(Allocation[] allocations)
Return an array of
Allocations. |
void |
trim(int targetSize)
Hints to the
Allocator that it should make a best effort to release any memory that it
has allocated, beyond the specified target number of bytes. |
public DefaultAllocator(int individualAllocationSize)
individualAllocationSize - The length of each individual allocation.public DefaultAllocator(int individualAllocationSize,
int initialAllocationCount)
Allocations created up front.
Note: Initial Allocations will never be discarded by trim(int).
individualAllocationSize - The length of each individual allocation.initialAllocationCount - The number of allocations to create up front.public Allocation allocate()
AllocatorAllocation.
When the caller has finished with the Allocation, it should be returned by calling
Allocator.release(Allocation).
allocate in interface AllocatorAllocation.public void release(Allocation allocation)
AllocatorAllocation.release in interface Allocatorallocation - The Allocation being returned.public void release(Allocation[] allocations)
AllocatorAllocations.release in interface Allocatorallocations - The array of Allocations being returned.public void trim(int targetSize)
AllocatorAllocator that it should make a best effort to release any memory that it
has allocated, beyond the specified target number of bytes.public int getTotalBytesAllocated()
AllocatorgetTotalBytesAllocated in interface Allocatorpublic void blockWhileTotalBytesAllocatedExceeds(int limit)
throws InterruptedException
AllocatorblockWhileTotalBytesAllocatedExceeds in interface Allocatorlimit - The limit in bytes.InterruptedException - If the thread is interrupted.public int getIndividualAllocationLength()
AllocatorAllocation.getIndividualAllocationLength in interface Allocator