Class SimpleDirectBufferAllocator

java.lang.Object
com.banuba.sdk.player.SimpleDirectBufferAllocator
All Implemented Interfaces:
IDirectBufferAllocator

public class SimpleDirectBufferAllocator extends Object implements IDirectBufferAllocator
A simple buffer allocator helps avoid unnecessary memory reallocations, thereby improving performance and reducing power consumption.
  • Constructor Details

    • SimpleDirectBufferAllocator

      public SimpleDirectBufferAllocator()
      Create a SimpleDirectBufferAllocator with default queue capacity - 3
    • SimpleDirectBufferAllocator

      public SimpleDirectBufferAllocator(int capacity)
      Create a SimpleDirectBufferAllocator with specified queue capacity. Important! capacity - should not be too large, otherwise the RAM may run out after a few iterations of use.
      Parameters:
      capacity - - queue size
  • Method Details

    • allocateBuffer

      @NonNull public ByteBuffer allocateBuffer(int capacity)
      The method returns a byte buffer of the required size from the buffer queue, or allocates a new buffer and returns it.
      Specified by:
      allocateBuffer in interface IDirectBufferAllocator
      Parameters:
      capacity - - required buffer size in bytes
      Returns:
      a new ByteBuffer or ByteBuffer from a queue with the specified size
    • retainBuffer

      public void retainBuffer(@NonNull ByteBuffer buffer)
      Retain a buffer to the buffers queue. This method should be called when the memory buffer is no longer needed for use.
      Parameters:
      buffer - - a buffer that needs to be returned back to the queue
    • clear

      public void clear()
      Clear the buffers queue