Class ObjectPool
Utility methods for ObjectPool<T>.
public static class ObjectPool
- Inheritance
-
ObjectPool
- Inherited Members
Methods
CreateInstance<T>()
Creates a new instance of T using its parameterless constructor.
If the parameterless constructor is not found, it will instead throw when executed for a reference type, or use default for value type.
public static T CreateInstance<T>()
Returns
- T
New instance of
T.
Type Parameters
T
Remarks
This is quite similar to CreateInstance<T>(), but attempts to be more performant.
Exceptions
- MissingMethodException
Thrown when the
Tis a reference type and has no public parameterless constructor, or in other words, when get_SupportInstantiation<T> is false.
get_Factory<T>()
Retrieves a factory method that creates new instances of T using its parameterless constructor.
If the parameterless constructor is not found, the delegate will instead throw when executed for a reference type, or use default for value type.
public static Func<T> get_Factory<T>()
Returns
- Func<T>
Type Parameters
T
Remarks
This is quite similar to CreateInstance<T>(), but attempts to be more performant.
get_Shared<T>()
Retrieves a shared ObjectPool<T> instance.
The shared pool has the following features:
- Instantiates new elements when empty using the parameterless constructor (or default for value types if missing) of
T. - Resize itself to accommodate all returned elements to the pool.
- Periodically trims itself removing old elements from the pool (GC-triggered).
- Is thread-safe.
public static ObjectPool<T> get_Shared<T>()
Returns
- ObjectPool<T>
Type Parameters
T
get_SupportsInstantiation<T>()
Gets a value indicating whether instantiation of the specific element type T is supported.
Reference types without a public parameterless constructor are not supported.
Is this value is true, then get_Factory<T>() and CreateInstance<T>() will create instances when used. If false, they will throw MissingMethodException instead.
public static bool get_SupportsInstantiation<T>()
Returns
Type Parameters
T