ResourcePoolT Class |
Namespace: DigitalRune
The ResourcePoolT type exposes the following members.
Name | Description | |
---|---|---|
ResourcePoolT |
Initializes a new instance of the ResourcePoolT class with the given
un-/initialize methods.
|
Name | Description | |
---|---|---|
Clear |
Removes all items from the resource pool.
(Overrides ResourcePoolClear.) | |
Equals | (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
Obtain |
Obtains a new item by reusing an instance from the pool or by creating a new instance if
necessary.
| |
Recycle |
Recycles the given item and places it back in the pool for future reuse.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
// 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.
// 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;