Pools

class Pools(source)

Helper class for creating pools of objects. An example use looks like this:

class MyPooledClass {

fun recycle() {
// Clear state if needed, then return this instance to the Pool
pool.release(this)
}

companion object {
private val pool = Pools.SynchronizedPool<MyPooledClass>(10)

fun obtain() : MyPooledClass {
// Get an instance from the Pool or
// construct a new one if none are available
return pool.acquire() ?: MyPooledClass()
}
}
}

Types

Link copied to clipboard
interface Pool<T : Any>

Interface for managing a pool of objects.

Link copied to clipboard
open class SimplePool<T : Any>(@IntRange(from = 1) maxPoolSize: Int) : Pools.Pool<T>

Simple (non-synchronized) pool of objects.

Link copied to clipboard
open class SynchronizedPool<T : Any>(maxPoolSize: Int) : Pools.SimplePool<T>

Synchronized pool of objects.