Hexagon
Loading...
Searching...
No Matches
Hexagon.Pool< T > Class Template Referencesealed

Manages a collection of objects that can be reused, tracking their state via a delegate. This implementation relies on an external function to determine if an object is active or inactive. Operations that search for objects, such as Get() or ViewExistingInactive(out T?), have a performance cost that scales linearly with the total number of items.
See Pool notes Hexagon Pool Notes. More...

Public Member Functions

void Populate (int delta)
 Creates and adds a specified number of new items to the pool using the factory function.
 
Get ()
 Retrieves an inactive object from the pool. If none are available, a new one is created and added to the pool.
 
Get (T item)
 Marks a specific, known item as active, invoking the OnGet action on it.
 
bool ViewExistingInactive ([NotNullWhen(true)] out T? result)
 Finds the first inactive object in the pool without changing its state.
 
bool ViewExistingActive ([NotNullWhen(true)] out T? result)
 Finds the first active object in the pool without changing its state.
 
void Release (T item)
 Informs the pool that an item is no longer in use, invoking the OnRelease action on it.
 
void ReleaseAll ()
 Releases all objects in the pool that are currently considered active.
 

Static Public Member Functions

static Pool< T > Create (Func< T > factory, Action< T > onGet, Action< T > onRelease, Func< T, bool > isActive, int listCapacity=20)
 Creates and initializes a new instance of the Pool<T>.
 

Properties

int TotalCount [get]
 The total number of objects currently managed by the pool, both active and inactive.
 
int InactiveCount [get]
 The current number of inactive objects in the pool.
 
int ActiveCount [get]
 The current number of objects considered active by the pool.
 

Detailed Description

Manages a collection of objects that can be reused, tracking their state via a delegate. This implementation relies on an external function to determine if an object is active or inactive. Operations that search for objects, such as Get() or ViewExistingInactive(out T?), have a performance cost that scales linearly with the total number of items.
See Pool notes Hexagon Pool Notes.

Template Parameters
TThe type of object to be managed. Must be a class.
Type Constraints
T :class 

Member Function Documentation

◆ Create()

static Pool< T > Hexagon.Pool< T >.Create ( Func< T > factory,
Action< T > onGet,
Action< T > onRelease,
Func< T, bool > isActive,
int listCapacity = 20 )
inlinestatic

Creates and initializes a new instance of the Pool<T>.

Parameters
factoryThe function used to create new object instances.
onGetThe action to perform on an object when it is retrieved from the pool.
onReleaseThe action to perform on an object when it is returned to the pool.
isActiveThe function that determines if an object is currently active.
listCapacityThe initial capacity of the internal list that stores the objects.
Returns
A new, configured instance of the pool.

◆ Get() [1/2]

T Hexagon.Pool< T >.Get ( )
inline

Retrieves an inactive object from the pool. If none are available, a new one is created and added to the pool.

Returns
An object ready for use.

◆ Get() [2/2]

T Hexagon.Pool< T >.Get ( T item)
inline

Marks a specific, known item as active, invoking the OnGet action on it.

This method is intended to be used on an item that has been retrieved via ViewExistingInactive.

Parameters
itemThe item to formally get.
Returns
The item that was passed in.

◆ Populate()

void Hexagon.Pool< T >.Populate ( int delta)
inline

Creates and adds a specified number of new items to the pool using the factory function.

Parameters
deltaThe number of new items to create and add.

◆ Release()

void Hexagon.Pool< T >.Release ( T item)
inline

Informs the pool that an item is no longer in use, invoking the OnRelease action on it.

Parameters
itemThe item to release.

◆ ReleaseAll()

void Hexagon.Pool< T >.ReleaseAll ( )
inline

Releases all objects in the pool that are currently considered active.

◆ ViewExistingActive()

bool Hexagon.Pool< T >.ViewExistingActive ( [NotNullWhen(true)] out T? result)
inline

Finds the first active object in the pool without changing its state.

Parameters
resultThe active object, if one was found; otherwise, null.
Returns
true if an active object was found; otherwise, false.

◆ ViewExistingInactive()

bool Hexagon.Pool< T >.ViewExistingInactive ( [NotNullWhen(true)] out T? result)
inline

Finds the first inactive object in the pool without changing its state.

Parameters
resultThe inactive object, if one was found; otherwise, null.
Returns
true if an inactive object was found; otherwise, false.

Property Documentation

◆ ActiveCount

int Hexagon.Pool< T >.ActiveCount
get

The current number of objects considered active by the pool.

◆ InactiveCount

int Hexagon.Pool< T >.InactiveCount
get

The current number of inactive objects in the pool.

◆ TotalCount

int Hexagon.Pool< T >.TotalCount
get

The total number of objects currently managed by the pool, both active and inactive.


The documentation for this class was generated from the following file: