koblas

Workspace

Reusable scratch buffers, pooled by width. Every borrow outstanding at the same time gets a different buffer, so nesting is safe. Not thread-safe, deliberately: sharing one across threads corrupts results.

A borrow is always exactly the width asked for, so a caller whose sizes vary opens a pool per width. Pools sit in most-recently-used order, and past 64 of them the coldest idle pool is dropped to bound what one workspace holds. A pool with a buffer still lent out is never dropped.

take lends double-precision buffers, the element type an unqualified borrow means. An element type added later gets a borrow and a return of its own over the same ArrayPools, and its buffers are pooled apart from these: a pool lends one array type, so the 64 widths are counted per element type.

Constructors

Workspace

constructor()(source)

Functions

release

fun release(buffer: DoubleArray)(source)

Returns a buffer from take to its pool.

reserve

fun reserve(size: Int, count: Int)(source)

Pre-allocates count buffers of size, so a loop does not allocate even on its first pass.

take

fun take(size: Int): DoubleArray(source)

Borrows a vector of size, which must be released; contents are undefined. Prefer borrow.

Link copied to clipboard
inline fun <T> Workspace?.borrow(size: Int, block: (DoubleArray) -> T): T

Borrows a vector of size for block, allocating one when there is no workspace to lend it.