Class ComponentArrayPoolManager
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Core.dll
Per-world manager for pooled component arrays. Provides pooled arrays for component storage, reducing garbage collection pressure. Uses .NET's built-in ArrayPool<T>.Shared for efficient memory reuse.
public sealed class ComponentArrayPoolManager
- Inheritance
-
ComponentArrayPoolManager
- Inherited Members
Remarks
This manager is instance-based, with one instance per World. Each World has its own independent pool statistics and tracking, enabling true multi-world isolation.
Rented arrays may be larger than requested due to ArrayPool's bucketing strategy. Always track the actual count of elements separately from the array length.
Properties
OutstandingCount
Gets the number of arrays currently rented (not returned).
public long OutstandingCount { get; }
Property Value
TotalRented
Gets the total number of arrays rented from this pool.
public long TotalRented { get; }
Property Value
TotalReturned
Gets the total number of arrays returned to this pool.
public long TotalReturned { get; }
Property Value
Methods
Register<T>()
Registers a component type for non-generic pool access.
public static void Register<T>() where T : struct
Type Parameters
TThe component type to register.
Remarks
This method should be called during initialization for all component types that will be accessed via the non-generic Rent(Type, int) and Return(Type, Array, bool) methods. This is required for AOT compatibility.
Rent(Type, int)
Rents an array for the specified component type.
public Array Rent(Type componentType, int minimumLength)
Parameters
Returns
- Array
A boxed array of the appropriate type.
Remarks
For AOT compatibility, the component type must be registered via Register<T>() before calling this method. For known types at compile time, use Rent<T>(int) directly instead.
Exceptions
- InvalidOperationException
Thrown when the component type has not been registered via Register<T>().
Rent<T>(int)
Rents an array of at least the specified minimum length.
public T[] Rent<T>(int minimumLength) where T : struct
Parameters
minimumLengthintThe minimum required length.
Returns
- T[]
An array of at least the specified length.
Type Parameters
TThe component type.
Remarks
The returned array may be longer than requested. Track the actual element count separately. When done, return the array using Return<T>(T[], bool).
Return(Type, Array, bool)
Returns an array to the pool for the specified component type.
public void Return(Type componentType, Array array, bool clearArray = false)
Parameters
componentTypeTypeThe component type.
arrayArrayThe array to return.
clearArrayboolWhether to clear the array contents.
Remarks
For AOT compatibility, the component type must be registered via Register<T>() before calling this method. For known types at compile time, use Return<T>(T[], bool) directly instead.
Exceptions
- InvalidOperationException
Thrown when the component type has not been registered via Register<T>().
Return<T>(T[], bool)
Returns an array to the pool.
public void Return<T>(T[] array, bool clearArray = false) where T : struct
Parameters
arrayT[]The array to return.
clearArrayboolWhether to clear the array contents before returning.
Type Parameters
TThe component type.
Remarks
It is recommended to set clearArray to true for
reference types or when arrays may contain sensitive data.
After calling this method, the caller should not access the array again.