DefaultAllocator
@UnstableApi
public final class DefaultAllocator implements Allocator
Default implementation of Allocator.
Summary
Public constructors |
|---|
DefaultAllocator(boolean trimOnReset, int individualAllocationSize)Constructs an instance without creating any |
DefaultAllocator(Constructs an instance with some |
Public methods |
|
|---|---|
synchronized Allocation |
allocate()Obtain an |
int |
Returns the length of each individual |
synchronized int |
Returns the total number of bytes currently allocated. |
synchronized void |
release(Allocation allocation)Releases an |
synchronized void |
release(@Nullable Allocator.AllocationNode allocationNode)Releases all |
synchronized void |
reset() |
synchronized void |
setTargetBufferSize(int targetBufferSize) |
synchronized void |
trim()Hints to the allocator that it should make a best effort to release any excess |
Public constructors
DefaultAllocator
public DefaultAllocator(boolean trimOnReset, int individualAllocationSize)
Constructs an instance without creating any Allocations up front.
| Parameters | |
|---|---|
boolean trimOnReset |
Whether memory is freed when the allocator is reset. Should be true unless the allocator will be re-used by multiple player instances. If set to false, trimming can be forced by calling |
int individualAllocationSize |
The length of each individual |
DefaultAllocator
public DefaultAllocator(
boolean trimOnReset,
int individualAllocationSize,
int initialAllocationCount
)
Constructs an instance with some Allocations created up front.
Note: Allocations created up front will never be discarded by trim.
| Parameters | |
|---|---|
boolean trimOnReset |
Whether memory is freed when the allocator is reset. Should be true unless the allocator will be re-used by multiple player instances. If set to false, trimming can be forced by calling |
int individualAllocationSize |
The length of each individual |
int initialAllocationCount |
The number of allocations to create up front. |
Public methods
allocate
synchronized public Allocation allocate()
Obtain an Allocation.
When the caller has finished with the Allocation, it should be returned by calling release.
| Returns | |
|---|---|
Allocation |
The |
getIndividualAllocationLength
public int getIndividualAllocationLength()
Returns the length of each individual Allocation.
getTotalBytesAllocated
synchronized public int getTotalBytesAllocated()
Returns the total number of bytes currently allocated.
release
synchronized public void release(Allocation allocation)
Releases an Allocation back to the allocator.
| Parameters | |
|---|---|
Allocation allocation |
The |
release
synchronized public void release(@Nullable Allocator.AllocationNode allocationNode)
Releases all Allocations in the chain starting at the given AllocationNode.
Implementations must not make memory allocations.
trim
synchronized public void trim()
Hints to the allocator that it should make a best effort to release any excess Allocations.