class RemiLib::ArrayPool(T)
- RemiLib::ArrayPool(T)
- Reference
- Object
Overview
The ArrayPool class provides functionality to allow an array of a desired
size to be 'rented' out so that buffers of the same size don't need to be
constantly re-created.
These are not thread safe. If you need to use array pools with multiple
threads, create one ArrayPool instance directly per thread.
Defined in:
remilib/arraypool.crConstructors
-
.new(defaultVal : T)
Creates a new
ArrayPoolinstance.
Instance Method Summary
-
#clear : Nil
Removes all arrays from the pool and marks them as not rented.
-
#rent(size) : Array(T)
Requests an
Array(T)ofsizeelements from the pool. -
#return(array)
Lets the array pool know that you are done using
arrayso that it can mark it as not rented. -
#withRentedArray(size, &)
Rents out an array of
sizeelements, then yields it to the block.
Constructor Detail
Creates a new ArrayPool instance.
defaultVal is the default value assigned to each index when creating
NEW arrays. Existing arrays are not re-initialized with defaultVal
between rentings.
Instance Method Detail
Requests an Array(T) of size elements from the pool. If an
array of that size already exists and is not yet rented, it is returned
and set as 'rented'. Otherwise a new array of that size is created, set
as 'rented', and returned.
IMPORTANT: No effort is made to clear out the contents of old arrays before returning one.
Lets the array pool know that you are done using array so that it can
mark it as not rented. After calling this, you should not use array
anymore without first re-renting it with ArrayPool.rent.
Rents out an array of size elements, then yields it to the block. The
block is wrapped in a begin..ensure that will automatically return the
array when the block exits.