Package com.google.android.exoplayer2.upstream

## Class DefaultAllocator

- java.lang.Object
- - com.google.android.exoplayer2.upstream.DefaultAllocator

- All Implemented Interfaces:
    `Allocator`

      public final class DefaultAllocator
      extends Object
      implements Allocator

  Default implementation of `Allocator`.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultAllocator​(boolean trimOnReset, int individualAllocationSize)` | Constructs an instance without creating any `Allocation`s up front.
    `DefaultAllocator​(boolean trimOnReset, int individualAllocationSize, int initialAllocationCount)` | Constructs an instance with some `Allocation`s created up front.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Allocation` | `allocate()` | Obtain an `Allocation`.
    `int` | `getIndividualAllocationLength()` | Returns the length of each individual `Allocation`.
    `int` | `getTotalBytesAllocated()` | Returns the total number of bytes currently allocated.
    `void` | `release​(Allocation allocation)` | Releases an `Allocation` back to the allocator.
    `void` | `release​(Allocation[] allocations)` | Releases an array of `Allocation`s back to the allocator.
    `void` | `reset()` |
    `void` | `setTargetBufferSize​(int targetBufferSize)` |
    `void` | `trim()` | Hints to the allocator that it should make a best effort to release any excess `Allocation`s.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultAllocator

          public DefaultAllocator​(boolean trimOnReset,
                                  int individualAllocationSize)

      Constructs an instance without creating any `Allocation`s up front.
      Parameters:
        `trimOnReset` - Whether memory is freed when the allocator is reset. Should be true unless the allocator will be re-used by multiple player instances.
        `individualAllocationSize` - The length of each individual `Allocation`.

    - #### DefaultAllocator

          public DefaultAllocator​(boolean trimOnReset,
                                  int individualAllocationSize,
                                  int initialAllocationCount)

      Constructs an instance with some `Allocation`s created up front.

      Note: `Allocation`s created up front will never be discarded by `trim()`.

      Parameters:
        `trimOnReset` - Whether memory is freed when the allocator is reset. Should be true unless the allocator will be re-used by multiple player instances.
        `individualAllocationSize` - The length of each individual `Allocation`.
        `initialAllocationCount` - The number of allocations to create up front.

  - ### Method Detail

    - #### reset

          public void reset()

    - #### setTargetBufferSize

          public void setTargetBufferSize​(int targetBufferSize)

    - #### allocate

          public Allocation allocate()

      Description copied from interface: `Allocator`
      Obtain an `Allocation`.

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

      Specified by:
        `allocate` in interface `Allocator`
      Returns:
        The `Allocation`.

    - #### release

          public void release​(Allocation allocation)

      Description copied from interface: `Allocator`
      Releases an `Allocation` back to the allocator.
      Specified by:
        `release` in interface `Allocator`
      Parameters:
        `allocation` - The `Allocation` being released.

    - #### release

          public void release​(Allocation[] allocations)

      Description copied from interface: `Allocator`
      Releases an array of `Allocation`s back to the allocator.
      Specified by:
        `release` in interface `Allocator`
      Parameters:
        `allocations` - The array of `Allocation`s being released.

    - #### trim

          public void trim()

      Description copied from interface: `Allocator`
      Hints to the allocator that it should make a best effort to release any excess `Allocation`s.
      Specified by:
        `trim` in interface `Allocator`

    - #### getTotalBytesAllocated

          public int getTotalBytesAllocated()

      Description copied from interface: `Allocator`
      Returns the total number of bytes currently allocated.
      Specified by:
        `getTotalBytesAllocated` in interface `Allocator`

    - #### getIndividualAllocationLength

          public int getIndividualAllocationLength()

      Description copied from interface: `Allocator`
      Returns the length of each individual `Allocation`.
      Specified by:
        `getIndividualAllocationLength` in interface `Allocator`