Click or drag to resize
DigitalRuneResourcePoolT Class
Manages a pool of typed, reusable items. (Thread-safe)
Inheritance Hierarchy
SystemObject
  DigitalRuneResourcePool
    DigitalRuneResourcePoolT

Namespace: DigitalRune
Assembly: DigitalRune (in DigitalRune.dll) Version: 1.20.0.0 (1.20.1.14552)
Syntax
public class ResourcePool<T> : ResourcePool
where T : class

Type Parameters

T
The type of the items.

The ResourcePoolT type exposes the following members.

Constructors
  NameDescription
Public methodResourcePoolT
Initializes a new instance of the ResourcePoolT class with the given un-/initialize methods.
Top
Methods
  NameDescription
Public methodClear
Removes all items from the resource pool.
(Overrides ResourcePoolClear.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodObtain
Obtains a new item by reusing an instance from the pool or by creating a new instance if necessary.
Public methodRecycle
Recycles the given item and places it back in the pool for future reuse.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks
Thread-Safety: The ResourcePoolT is thread-safe. It is safe to access a resource pool from multiple threads simultaneously.
Examples
The following demonstrates how to create a resource pool.
C#
// Resource pools are usually static members of a type.
public static readonly ResourcePool<List<float>> MyPool = 
  new ResourcePool<List<float>> (
    () => new List<float>(),   // Create
    null,                      // Initialize (not needed for List<float>)
    list => list.Clear());     // Uninitialize

Note: The example above creates a resource pools for ListT for a certain type. DigitalRune already provides such a resource pool (see ResourcePoolsT), so it is actually not required to create your own.

The following demonstrates how to use the resource pool created in example above.

C#
// Instead of calling 
//   List<float> myList = new List<float>(); 
// reuse existing list from resource pool.
List<float> myList = MyPool.Obtain();

// Do something with myList.
...

// Return myList to resource pool when no longer needed.
MyPool.Recycle(myList);
myList = null;
See Also