ByteBufferPool

class ByteBufferPool : DefaultPool<ByteBuffer>

Constructors

<init>

ByteBufferPool(
    capacity: Int = DEFAULT_POOL_CAPACITY,
    bufferSize: Int = DEFAULT_BUFFER_SIZE)

Properties

bufferSize

val bufferSize: Int

Inherited Properties

capacity

val capacity: Int

Pool capacity.

Functions

clearInstance

fun clearInstance(instance: ByteBuffer): ByteBuffer

produceInstance

fun produceInstance(): ByteBuffer

validateInstance

fun validateInstance(instance: ByteBuffer): Unit

Inherited Functions

borrow

fun borrow(): T

borrow an instance. Pool can recycle an old instance or create a new one

dispose

fun dispose(): Unit

Dispose the whole pool. None of borrowed objects could be used after the pool gets disposed otherwise it can result in undefined behaviour

disposeInstance

open fun disposeInstance(instance: T): Unit

Dispose instance and release it’s resources

recycle

fun recycle(instance: T): Unit

Recycle an instance. Should be recycled what was borrowed before otherwise could fail

Extension Functions

useBorrowed

fun <T : Any, R> ObjectPool<T>.useBorrowed(
    block: (T) -> R
): R

Borrows and instance of T from the pool, invokes block with it and finally recycles it

useInstance

fun <T : Any, R> ObjectPool<T>.useInstance(
    block: (T) -> R
): R

Borrows and instance of T from the pool, invokes block with it and finally recycles it