Class KeyedSharedPool<T, TKey>
Provides a pool of shared objects organized by a key. The key is used both to group interchangeable objects as well as a parameter to the object allocation function.
Namespace: Microsoft.Psi
Assembly: Microsoft.Psi.dll
Syntax
public class KeyedSharedPool<T, TKey> : IDisposable where T : class
Type Parameters
Name | Description |
---|---|
T | The type of the objects managed by this pool. |
TKey | The type of the key. |
Constructors
View SourceKeyedSharedPool(Func<TKey, T>, Int32)
Initializes a new instance of the KeyedSharedPool<T, TKey> class.
Declaration
public KeyedSharedPool(Func<TKey, T> allocator, int initialSize = 10)
Parameters
Type | Name | Description |
---|---|---|
Func<TKey, T> | allocator | The allocation function for constructing a new object. |
System.Int32 | initialSize | Initial size of each pool. |
Methods
View SourceDispose()
Declaration
public void Dispose()
GetOrCreate(TKey)
Get or creates a shared object from the pool.
Declaration
public Shared<T> GetOrCreate(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The shared object key. |
Returns
Type | Description |
---|---|
Shared<T> | A shared object from the pool. |
Reset(Boolean)
Resets the keyed shared pool.
Declaration
public void Reset(bool clearLiveObjects = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | clearLiveObjects | Indicates whether to clear any live objects. |
Remarks
If the clearLiveObjects flag is false, an exception is thrown if a reset is attempted while the pool still contains live objects.
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |