DefaultAllocator


@UnstableApi
class DefaultAllocator : Allocator


Default implementation of Allocator.

Summary

Public constructors

DefaultAllocator(trimOnReset: Boolean, individualAllocationSize: Int)

Constructs an instance without creating any Allocations up front.

DefaultAllocator(
    trimOnReset: Boolean,
    individualAllocationSize: Int,
    initialAllocationCount: Int
)

Constructs an instance with some Allocations created up front.

Public functions

synchronized Allocation!

Obtain an Allocation.

Int

Returns the length of each individual Allocation.

synchronized Int

Returns the total number of bytes currently allocated.

synchronized Unit
release(allocation: Allocation!)

Releases an Allocation back to the allocator.

synchronized Unit

Releases all Allocations in the chain starting at the given .

synchronized Unit
synchronized Unit
setTargetBufferSize(targetBufferSize: Int)
synchronized Unit

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

Public constructors

DefaultAllocator

DefaultAllocator(trimOnReset: Boolean, individualAllocationSize: Int)

Constructs an instance without creating any Allocations up front.

Parameters
trimOnReset: Boolean

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 setTargetBufferSize manually when required.

individualAllocationSize: Int

The length of each individual Allocation.

DefaultAllocator

DefaultAllocator(
    trimOnReset: Boolean,
    individualAllocationSize: Int,
    initialAllocationCount: Int
)

Constructs an instance with some Allocations created up front.

Note: Allocations created up front will never be discarded by trim.

Parameters
trimOnReset: Boolean

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 setTargetBufferSize manually when required.

individualAllocationSize: Int

The length of each individual Allocation.

initialAllocationCount: Int

The number of allocations to create up front.

Public functions

allocate

synchronized fun allocate(): Allocation!

Obtain an Allocation.

When the caller has finished with the Allocation, it should be returned by calling release.

Returns
Allocation!

The Allocation.

getIndividualAllocationLength

fun getIndividualAllocationLength(): Int

Returns the length of each individual Allocation.

getTotalBytesAllocated

synchronized fun getTotalBytesAllocated(): Int

Returns the total number of bytes currently allocated.

release

synchronized fun release(allocation: Allocation!): Unit

Releases an Allocation back to the allocator.

Parameters
allocation: Allocation!

The Allocation being released.

release

synchronized fun release(allocationNode: Allocator.AllocationNode?): Unit

Releases all Allocations in the chain starting at the given .

Implementations must not make memory allocations.

reset

synchronized fun reset(): Unit

setTargetBufferSize

synchronized fun setTargetBufferSize(targetBufferSize: Int): Unit

trim

synchronized fun trim(): Unit

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