https://github.com/tpapp/objectpools.jl
An implementation of user-managed object pools in Julia.
https://github.com/tpapp/objectpools.jl
Last synced: over 1 year ago
JSON representation
An implementation of user-managed object pools in Julia.
- Host: GitHub
- URL: https://github.com/tpapp/objectpools.jl
- Owner: tpapp
- License: other
- Created: 2019-11-04T13:50:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-20T09:17:26.000Z (over 5 years ago)
- Last Synced: 2025-02-28T16:20:12.234Z (over 1 year ago)
- Language: Julia
- Size: 4.88 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ObjectPools.jl

[](https://travis-ci.com/tpapp/ObjectPools.jl)
[](http://codecov.io/github/tpapp/ObjectPools.jl?branch=master)
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:
```julia
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`.