Constructor and Description |
---|
DefaultAllocator(int individualAllocationSize)
Constructs an initially empty pool.
|
DefaultAllocator(int individualAllocationSize,
int initialAllocationCount)
Constructs a pool with some
Allocation s 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
Allocation s. |
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)
Allocation
s created up front.
Note: Initial Allocation
s 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()
Allocator
Allocation
.
When the caller has finished with the Allocation
, it should be returned by calling
Allocator.release(Allocation)
.
allocate
in interface Allocator
Allocation
.public void release(Allocation allocation)
Allocator
Allocation
.release
in interface Allocator
allocation
- The Allocation
being returned.public void release(Allocation[] allocations)
Allocator
Allocation
s.release
in interface Allocator
allocations
- The array of Allocation
s being returned.public void trim(int targetSize)
Allocator
Allocator
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()
Allocator
getTotalBytesAllocated
in interface Allocator
public void blockWhileTotalBytesAllocatedExceeds(int limit) throws InterruptedException
Allocator
blockWhileTotalBytesAllocatedExceeds
in interface Allocator
limit
- The limit in bytes.InterruptedException
- If the thread is interrupted.public int getIndividualAllocationLength()
Allocator
Allocation
.getIndividualAllocationLength
in interface Allocator