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 Allocations up front.

DefaultAllocator(
    boolean trimOnReset,
    int individualAllocationSize,
    int initialAllocationCount
)

Constructs an instance with some Allocations created up front.

Public methods

synchronized Allocation

Obtain an Allocation.

int

Returns the length of each individual Allocation.

synchronized int

Returns the total number of bytes currently allocated.

synchronized void
release(Allocation allocation)

Releases an Allocation back to the allocator.

synchronized void

Releases all Allocations in the chain starting at the given .

synchronized void
synchronized void
setTargetBufferSize(int targetBufferSize)
synchronized void

Hints to the allocator that it should make a best effort to release any excess Allocations.

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.

int individualAllocationSize

The length of each individual Allocation.

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.

int individualAllocationSize

The length of each individual Allocation.

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 Allocation.

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 Allocation being released.

release

synchronized public void release(@Nullable Allocator.AllocationNode allocationNode)

Releases all Allocations in the chain starting at the given .

Implementations must not make memory allocations.

reset

synchronized public void reset()

setTargetBufferSize

synchronized public void setTargetBufferSize(int targetBufferSize)

trim

synchronized public void trim()

Hints to the allocator that it should make a best effort to release any excess Allocations.