Skip to content

tpapp/ObjectPools.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ObjectPools.jl

Lifecycle Build Status codecov.io

An implementation of user-managed object pools in Julia.

Overview

This package is designed for use cases where some inner functions would need to allocate a large number of arrays which would not escape an outer function f. An object pool allows the user to obtain new objects with the new!, then allow them to be recycled with recycle!.

Consider this (contrived) example:

function f(pool, x::AbstractVector{T}) where T
    recycle!(pool)                   # reuse all arrays
    S = float(T)
    l = length(x)
    y = new!(pool, Vector{S}, l)     # taken from pool
    z = new!(pool, Matrix{S}, l, l)  # taken from pool
    @. y = abs2(x)
    z .= x .+ permutedims(x)
    z * y                            # the only allocated array
end

pool = ArrayPool() will save the relevant interim arrays and avoid allocation when necessary. If the function is called with various types, these will eventually accumulate too in pool.

About

An implementation of user-managed object pools in Julia.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages