ArenaPool <Type, Args>
Index
Constructors
constructor
Type parameters
- Type
- Args: unknown[] = []
Parameters
builder: (...args: [] | Args) => Type
optionalrecycler: NoInfer<(instance: Type, ...args: Args) => Type>
maxObjects: number = 100
Returns ArenaPool<Type, Args>
Properties
publicbuilder
Type declaration
Parameters
rest...args: [] | Args
Returns Type
publicdisableWarnings
publicindex
publicmaxObjects
publicobjects
publicoptionalrecycler
publictotalAllocations
Methods
borrow
Use a single instance out of th pool and immediately return it to the pool
Parameters
context: (object: Type) => void
Returns void
dispose
Returns void
done
Signals we are done with the pool objects for now, Reclaims all objects in the pool.
If a list of pooled objects is passed to done they are un-hooked from the pool and are free to be passed to consumers
Parameters
rest...objects: Type[]
A list of object to separate from the pool
Returns Type[]
get
Retrieve a value from the pool, will allocate a new instance if necessary or recycle from the pool
Returns Type
getWith
Retrieve a value from the pool like ArenaPool.get, passing arguments along. A new instance gets them from the builder, a reused instance is passed to the recycler with them. Without a recycler a reused instance comes back as it was.
The argument types come from the builder's parameters.
Parameters
rest...args: Args
Arguments for the builder or recycler
Returns Type
preallocate
Returns void
using
Use many instances out of the in the context and return all to the pool.
By returning values out of the context they will be un-hooked from the pool and are free to be passed to consumers
Parameters
context: (pool: ArenaPool<Type, Args>) => void | Type[]
Returns Type[]
This pool works like an arena allocator, it preallocates a large list of objects and passes them out sequentially It is meant to be freed all at once, so things that can be reclaimed after a frame are the ideal type.
If you need to take singular objects and put singular objects back RentalPool is ideal.
The builder can take arguments: ArenaPool.getWith passes them to the builder for a new instance or to the recycler for a reused one.
get(),preallocate()anddone()still build with no arguments, so give the builder's parameters defaults.