Constructor and Description |
---|
DefaultAllocator(boolean trimOnReset,
int individualAllocationSize)
Constructs an instance without creating any
Allocation s up front. |
DefaultAllocator(boolean trimOnReset,
int individualAllocationSize,
int initialAllocationCount)
Constructs an instance with some
Allocation s created up front. |
Modifier and Type | Method and Description |
---|---|
Allocation |
allocate()
Obtain an
Allocation . |
int |
getIndividualAllocationLength()
Returns the length of each individual
Allocation . |
int |
getTotalBytesAllocated()
Returns the total number of bytes currently allocated.
|
void |
release(Allocation allocation)
Releases an
Allocation back to the allocator. |
void |
release(Allocation[] allocations)
Releases an array of
Allocation s back to the allocator. |
void |
reset() |
void |
setTargetBufferSize(int targetBufferSize) |
void |
trim()
Hints to the allocator that it should make a best effort to release any excess
Allocation s. |
public DefaultAllocator(boolean trimOnReset, int individualAllocationSize)
Allocation
s up front.trimOnReset
- Whether memory is freed when the allocator is reset. Should be true unless
the allocator will be re-used by multiple player instances.individualAllocationSize
- The length of each individual Allocation
.public DefaultAllocator(boolean trimOnReset, int individualAllocationSize, int initialAllocationCount)
Allocation
s created up front.
Note: Allocation
s created up front will never be discarded by trim()
.
trimOnReset
- Whether memory is freed when the allocator is reset. Should be true unless
the allocator will be re-used by multiple player instances.individualAllocationSize
- The length of each individual Allocation
.initialAllocationCount
- The number of allocations to create up front.public void reset()
public void setTargetBufferSize(int targetBufferSize)
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
back to the allocator.release
in interface Allocator
allocation
- The Allocation
being released.public void release(Allocation[] allocations)
Allocator
Allocation
s back to the allocator.release
in interface Allocator
allocations
- The array of Allocation
s being released.public void trim()
Allocator
Allocation
s.public int getTotalBytesAllocated()
Allocator
getTotalBytesAllocated
in interface Allocator
public int getIndividualAllocationLength()
Allocator
Allocation
.getIndividualAllocationLength
in interface Allocator