This generic class implements an object pool. More...
Public Member Functions | |
T | Get () |
Gets an object from the pool. | |
void | Release (T item) |
Releases an object back to the pool. | |
void | Allocate (int initialSize) |
Preallocates a number of objects into the pool. | |
void | Trim (int max) |
Trims the pool to a maximum number of objects. | |
This generic class implements an object pool.
It helps prevent garbage collection stutter by reusing objects without allocating and deallocating memory.
T | : | new() |
|
inline |
Preallocates a number of objects into the pool.
initialSize | Initial size. |
|
inline |
Gets an object from the pool.
After getting an object, you should initialize its fields because it will have the values from its previous use.
|
inline |
Releases an object back to the pool.
item | Item. |
|
inline |
Trims the pool to a maximum number of objects.
max | Max objects. |