ArrayPool

ceramic.ArrayPool (Class)

A pool system for efficiently reusing arrays of fixed sizes.

ArrayPool reduces garbage collection pressure by reusing arrays instead of creating new ones. It maintains pools of arrays organized by size ranges, automatically returning arrays to the pool when they're no longer needed.

The pool uses predefined size buckets (10, 100, 1000, 10000, 100000) and automatically selects the appropriate pool based on the requested size.

Example usage:

// Get an array from the pool
var pool = ArrayPool.pool(50);
var array = pool.get();

// Use the array
for (i in 0...50) {
    array[i] = i * 2;
}

// Return to pool when done
pool.release(array);

Static Members

pool(size: Int): ArrayPool

Gets an appropriate array pool for the requested size. Automatically selects from predefined pools based on size ranges. For sizes over 100,000, creates a temporary pool (not recommended).

Name Type Description
size Int The maximum size of arrays needed
Returns Description
ArrayPool An ArrayPool instance suitable for the requested size

Instance Members

Gets a reusable array from the pool. The array may contain old data and should be cleared if needed.

Returns Description
ReusableArray<Any> A ReusableArray instance of the pool's configured size

release(array: ReusableArray<Any>): Void

Returns an array to the pool for reuse. The array is automatically cleared (all elements set to null).

Name Type Description
array ReusableArray<Any> The array to return to the pool

new(arrayLengths: Int): Void

Creates a new ArrayPool for arrays of the specified size.

Name Type Description
arrayLengths Int The size of arrays this pool will manage

Private Members

ALLOC_STEP: Int

dynPool10: ArrayPool

Pool for arrays up to 10 elements


dynPool100: ArrayPool

Pool for arrays up to 100 elements


dynPool1000: ArrayPool

Pool for arrays up to 1,000 elements


dynPool10000: ArrayPool

Pool for arrays up to 10,000 elements


dynPool100000: ArrayPool

Pool for arrays up to 100,000 elements


didNotifyLargePool: Bool

Flag to prevent spamming warnings about large pools


Storage for pooled arrays


nextFree: Int

Index of the next available slot in the pool


arrayLengths: Int

The size of arrays managed by this pool