DefaultAllocator
@UnstableApi
class DefaultAllocator : Allocator
Default implementation of Allocator.
Summary
Public constructors |
|---|
DefaultAllocator(trimOnReset: Boolean, individualAllocationSize: Int)Constructs an instance without creating any |
DefaultAllocator(Constructs an instance with some |
Public functions |
|
|---|---|
synchronized Allocation! |
allocate()Obtain an |
Int |
Returns the length of each individual |
synchronized Int |
Returns the total number of bytes currently allocated. |
synchronized Int |
Returns the total number of bytes currently occupied by unused allocations. |
synchronized Unit |
release(allocation: Allocation!)Releases an |
synchronized Unit |
release(allocationNode: Allocator.AllocationNode?)Releases all |
synchronized Unit |
reset() |
synchronized Unit |
setTargetBufferSize(targetBufferSize: Int) |
synchronized Unit |
trim()Hints to the allocator that it should make a best effort to release any excess |
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 |
individualAllocationSize: Int |
The length of each individual |
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 |
individualAllocationSize: Int |
The length of each individual |
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 |
getIndividualAllocationLength
fun getIndividualAllocationLength(): Int
Returns the length of each individual Allocation.
getTotalBytesAllocated
synchronized fun getTotalBytesAllocated(): Int
Returns the total number of bytes currently allocated.
getUnusedBytesAllocated
synchronized fun getUnusedBytesAllocated(): Int
Returns the total number of bytes currently occupied by unused allocations.
release
synchronized fun release(allocation: Allocation!): Unit
Releases an Allocation back to the allocator.
| Parameters | |
|---|---|
allocation: Allocation! |
The |
release
synchronized fun release(allocationNode: Allocator.AllocationNode?): Unit
Releases all Allocations in the chain starting at the given AllocationNode.
Implementations must not make memory allocations.
trim
synchronized fun trim(): Unit
Hints to the allocator that it should make a best effort to release any excess Allocations.