Skip to content

Latest commit

 

History

History
72 lines (52 loc) · 5.8 KB

Assorted.Utils.Collections.ObjectPool-1.md

File metadata and controls

72 lines (52 loc) · 5.8 KB

ObjectPool<T> Class

Namespace: Assorted.Utils.Collections
Assembly: Assorted.Utils (Assorted.Utils.dll) version 1.1.0.0
Implements: IDisposable
Inheritance: object ObjectPool<T>

Defines a pool of reusable objects.

Syntax

public class ObjectPool<T> : IDisposable
    where T : class

Type Parameters

T
Specifies the type of objects in the pool.

Constructors

Constructor Description
ObjectPool<T>() Initializes a new instance of ObjectPool<T> class without an upper bound capacity. When a new object needs to be initialized, the default constructor of the target type is used.
ObjectPool<T>(Action<T>) Initializes a new instance of ObjectPool<T> class without an upper bound capacity. When a new object needs to be initialized, the default constructor of the target type is used. The specified action is used to reset a consumed object.
ObjectPool<T>(Func<T>) Initializes a new instance of ObjectPool<T> class without an upper bound capacity. When a new object needs to be initialized, the specified initialization function is used.
ObjectPool<T>(Func<T>, Action<T>) Initializes a new instance of ObjectPool<T> class without an upper bound capacity. When a new object needs to be initialized, the specified initialization function is used. The specified action is used to reset a consumed object.
ObjectPool<T>(int) Initializes a new instance of ObjectPool<T> class with an upper bound capacity. When a new object needs to be initialized, the default constructor of the target type is used.
ObjectPool<T>(int, Action<T>) Initializes a new instance of ObjectPool<T> class with an upper bound capacity. When a new object needs to be initialized, the default constructor of the target type is used. The specified action is used to reset a consumed object.
ObjectPool<T>(int, Func<T>) Initializes a new instance of ObjectPool<T> class with an upper bound capacity. When a new object needs to be initialized, the specified initialization function is used. The specified action is used to reset a consumed object.
ObjectPool<T>(int, Func<T>, Action<T>) Initializes a new instance of ObjectPool<T> class with an upper bound capacity. When a new object needs to be initialized, the specified initialization function is used. The specified action is used to reset a consumed object.

Properties

Property Description
Count Gets the number of objects which are currently in the pool.
IsDisposed Gets whether this instance has been disposed.
MaxCapacity Gets the maximum number of objects that the pool is allowed to store.

Methods

Method Description
Acquire() Returns an object from the pool. If the pool is empty, a new object is initialized.
Clear() Clears the pool and disposes all the disposable objects in it.
Dispose() Releases all resources used by the ObjectPool<T>.
Dispose(bool) Releases the unmanaged resources used by the ObjectPool<T> and optionally releases the managed resources.
DisposeObject(T) Disposes the specified object if it implements the System.IDisposable interface.
Finalize() Finalizes the instance of ObjectPool<T> class.
Release(Proxy) Disposes a proxy object and puts its value back in the pool if the pool's maximum capacity has not been reached; otherwise, disposes the value too.
ReleaseObject(T) Puts an object back in the pool if the pool's maximum capacity has not been reached; otherwise, disposes the object.

Nested Types

Type Description
ObjectPool<T>.Proxy Wraps an object that has been acquired from an object pool.

Thread Safety

Any public member of this type, either static or instance, is thread-safe.

See Also


This document is generated by DG.