Manages a collection of objects that can be reused, tracking their state via a delegate.
More...
|
void | Populate (int delta) |
| Creates and adds a specified number of new items to the pool using the factory function.
|
|
T | Get () |
| Retrieves an inactive object from the pool. If none are available, a new one is created and added to the pool.
|
|
T | 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 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>.
|
|
|
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.
|
|
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
-
T | The type of object to be managed. Must be a class. |
◆ Create()
static Pool< T > 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
-
factory | The function used to create new object instances. |
onGet | The action to perform on an object when it is retrieved from the pool. |
onRelease | The action to perform on an object when it is returned to the pool. |
isActive | The function that determines if an object is currently active. |
listCapacity | The initial capacity of the internal list that stores the objects. |
- Returns
- A new, configured instance of the pool.
◆ Get() [1/2]
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 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
-
item | The item to formally get. |
- Returns
- The item that was passed in.
◆ Populate()
void Pool< T >.Populate |
( |
int | delta | ) |
|
|
inline |
Creates and adds a specified number of new items to the pool using the factory function.
- Parameters
-
delta | The number of new items to create and add. |
◆ Release()
void Pool< T >.Release |
( |
T | item | ) |
|
|
inline |
Informs the pool that an item is no longer in use, invoking the OnRelease action on it.
- Parameters
-
◆ ReleaseAll()
void Pool< T >.ReleaseAll |
( |
| ) |
|
|
inline |
Releases all objects in the pool that are currently considered active.
◆ ViewExistingActive()
bool Pool< T >.ViewExistingActive |
( |
[NotNullWhen(true)] out T? | result | ) |
|
|
inline |
Finds the first active object in the pool without changing its state.
- Parameters
-
result | The active object, if one was found; otherwise, null. |
- Returns
true
if an active object was found; otherwise, false
.
◆ ViewExistingInactive()
bool Pool< T >.ViewExistingInactive |
( |
[NotNullWhen(true)] out T? | result | ) |
|
|
inline |
Finds the first inactive object in the pool without changing its state.
- Parameters
-
result | The inactive object, if one was found; otherwise, null. |
- Returns
true
if an inactive object was found; otherwise, false
.
◆ ActiveCount
int Pool< T >.ActiveCount |
|
get |
The current number of objects considered active by the pool.
◆ InactiveCount
int Pool< T >.InactiveCount |
|
get |
The current number of inactive objects in the pool.
◆ TotalCount
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: