Package com.banuba.sdk.player
Class SimpleDirectBufferAllocator
java.lang.Object
com.banuba.sdk.player.SimpleDirectBufferAllocator
- All Implemented Interfaces:
IDirectBufferAllocator
A simple buffer allocator helps avoid unnecessary memory reallocations,
thereby improving performance and reducing power consumption.
-
Constructor Summary
ConstructorDescriptionCreate a SimpleDirectBufferAllocator with default queue capacity - 3SimpleDirectBufferAllocator
(int capacity) Create a SimpleDirectBufferAllocator with specified queue capacity. -
Method Summary
Modifier and TypeMethodDescriptionallocateBuffer
(int capacity) The method returns a byte buffer of the required size from the buffer queue, or allocates a new buffer and returns it.void
clear()
Clear the buffers queuevoid
retainBuffer
(ByteBuffer buffer) Retain a buffer to the buffers queue.
-
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
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 interfaceIDirectBufferAllocator
- Parameters:
capacity
- - required buffer size in bytes- Returns:
- a new ByteBuffer or ByteBuffer from a queue with the specified size
-
retainBuffer
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
-