# DefaultAllocator

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/upstream/DefaultAllocator.java+class:androidx.media3.exoplayer.upstream.DefaultAllocator)

*** ** * ** ***


```
@UnstableApi
class DefaultAllocator : Allocator
```

<br />

*** ** * ** ***

Default implementation of `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#DefaultAllocator(boolean,int)(trimOnReset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, individualAllocationSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Constructs an instance without creating any `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`s up front. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#DefaultAllocator(boolean,int,int)( trimOnReset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, individualAllocationSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, initialAllocationCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Constructs an instance with some `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`s created up front. |

| ### Public functions |
|---|---|
| `synchronized https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#allocate()()` Obtain an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#getIndividualAllocationLength()()` Returns the length of each individual `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#getTotalBytesAllocated()()` Returns the total number of bytes currently allocated. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#getUnusedBytesAllocated()()` Returns the total number of bytes currently occupied by unused allocations. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#release(androidx.media3.exoplayer.upstream.Allocation)(allocation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation!)` Releases an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation` back to the allocator. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#release(androidx.media3.exoplayer.upstream.Allocator.AllocationNode)(allocationNode: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator.AllocationNode?)` Releases all `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation` in the chain starting at the given `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator.AllocationNode`. |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#reset()()` |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#setTargetBufferSize(int)(targetBufferSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#trim()()` Hints to the allocator that it should make a best effort to release any excess `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`. |

## Public constructors

### DefaultAllocator

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

Constructs an instance without creating any `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`s up front.

| Parameters |
|---|---|
| `trimOnReset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#setTargetBufferSize(int)` manually when required. |
| `individualAllocationSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The length of each individual `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`. |

### DefaultAllocator

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

Constructs an instance with some `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`s created up front.

Note: `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`s created up front will never be discarded by `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#trim()`.

| Parameters |
|---|---|
| `trimOnReset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/DefaultAllocator#setTargetBufferSize(int)` manually when required. |
| `individualAllocationSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The length of each individual `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`. |
| `initialAllocationCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of allocations to create up front. |

## Public functions

### allocate

```
synchronized fun allocate(): Allocation!
```

Obtain an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`.

When the caller has finished with the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`, it should be returned by calling `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator#release(androidx.media3.exoplayer.upstream.Allocation)`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`. |

### getIndividualAllocationLength

```
fun getIndividualAllocationLength(): Int
```

Returns the length of each individual `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation` back to the allocator.

| Parameters |
|---|---|
| `allocation: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation!` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation` being released. |

### release

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

Releases all `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation` in the chain starting at the given `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocator.AllocationNode`.

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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Allocation`.