ObjectPool<TItem>

Overview

Object pool that calls the default constructor of the type passed as a generic parameter when creating new instances.

This object pool uses the Activator class to create a new instance.

Location


 

constructor

 

constructor

 

ObjectPool<TItem>()

 

Sub New()

constructor (PoolBehavior, Int32, Int32, Int32)

 

constructor(behavior: PoolBehavior; initialSize: Int32; maxSize: Int32; timeout: Int32)

 

ObjectPool<TItem>(PoolBehavior behavior, Int32 initialSize, Int32 maxSize, Int32 timeout)

 

Sub New(behavior As PoolBehavior, initialSize As Int32, maxSize As Int32, timeout As Int32)

Parameters:

  • behavior:
  • initialSize:
  • maxSize:
  • timeout:

constructor (PoolBehavior, Int32, Int32)  protected    (declared in BaseObjectPool<TItem>)

 

constructor(behavior: PoolBehavior; maxSize: Int32; timeout: Int32)

 

ObjectPool<TItem>(PoolBehavior behavior, Int32 maxSize, Int32 timeout)

 

Sub New(behavior As PoolBehavior, maxSize As Int32, timeout As Int32)

Parameters:

  • behavior:
  • maxSize:
  • timeout:

AcquiredInstancesCount    (declared in BaseObjectPool<TItem>)

Gets the count of the currently acquired object pool elements.

 

property AcquiredInstancesCount: Int32 read;

 

Int32 AcquiredInstancesCount { get; }

 

ReadOnly Property AcquiredInstancesCount() As Int32

AcquireInstance    (declared in BaseObjectPool<TItem>)

Acquires an item from the pool.

If there are non-acquired pool items or pool has an infinite size, the pool item is acquired and returned to the caller. Otherwise, the Behavior property specifies the result of the method call:

  • PoolBehavior.Wait - wait until any pool item becomes available.
  • PoolBehavior.IgnoreAndReturn - wait for no more than WaitTimeOut milliseconds for any pool items. If there still are no pool items available after timeout, null will be returned.
  • PoolBehavior.Raise - wait for no more than WaitTimeOut milliseconds for any pool items. If there still are no pool items available after timeout, an NoFreeObjectsInPoolException is raised.

 

method AcquireInstance: TItem

 

TItem AcquireInstance()

 

Function AcquireInstance() As TItem

Behavior    (declared in BaseObjectPool<TItem>)

Specifies the behavior of the object pool when an item is requested but the pool is empty (i.e. all available elements are acquired).

See the description of the AcquireInstance method for more details about possible Behavior settings.

 

property Behavior: PoolBehavior read write;

 

PoolBehavior Behavior { get; set; }

 

Property Behavior() As PoolBehavior

Clear    (declared in BaseObjectPool<TItem>)

Clears all items from the pool.

 

method Clear

 

void Clear()

 

Sub Clear()

Current    (declared in BaseObjectPool<TItem>)

Gets the current element in the collection.

This property is a part of the IEnumerator interface implementation.

 

property Current: Object read;

 

Object Current { get; }

 

ReadOnly Property Current() As Object

Dispose    (declared in BaseObjectPool<TItem>)

Releases all pool resources.

The FinalizePool method can be overridden in case some specific cleanup actions are needed.

 

method Dispose

 

void Dispose()

 

Sub Dispose()

DropInstance    (declared in BaseObjectPool<TItem>)

Removes the anItem object from the pool.

 

method DropInstance(item: TItem)

 

void DropInstance(TItem item)

 

Sub DropInstance(item As TItem)

Parameters:

  • item:

ExposeNonAcquiredInstances    (declared in BaseObjectPool<TItem>)

Exposes all non-acquired pool objects using the specified aDelegate.

 

method ExposeNonAcquiredInstances(action: ExposeNonAcquiredInstancesDelegate<TItem>)

 

void ExposeNonAcquiredInstances(ExposeNonAcquiredInstancesDelegate<TItem> action)

 

Sub ExposeNonAcquiredInstances(action As ExposeNonAcquiredInstancesDelegate<TItem>)

Parameters:

  • action:

FinalizePool  protected    (declared in BaseObjectPool<TItem>)

Finalizes the object pool.

This method's implementation is empty in the BaseObjectPool class but can be overriden in derived classes in case some specific cleanup actions are needed.

 

method FinalizePool

 

void FinalizePool()

 

Sub FinalizePool()

GetEnumerator    (declared in BaseObjectPool<TItem>)

Returns an enumerator that iterates through a collection of non-acquired pool objects.

This method is part of the IEnumerable interface implementation.

 

method GetEnumerator: IEnumerator

 

IEnumerator GetEnumerator()

 

Function GetEnumerator() As IEnumerator

Instances  protected    (declared in BaseObjectPool<TItem>)

Gets all pooled instances as a linked list.

This property can be used in the BaseObjectPool descendants to fine-tune pooled instances etc.

 

property Instances: LinkedList<TItem> read;

 

LinkedList<TItem> Instances { get; }

 

ReadOnly Property Instances() As LinkedList<TItem>

MaxPoolSize    (declared in BaseObjectPool<TItem>)

Gets the maximum number of items that can be contained in the pool.

-1 means the pool is of unlimited size.

It is not possible to set this property to a positive value less than the AcquiredInstancesCount, doing so will raise an exception. At the same time, it is always possible to set value of this property to -1.

 

property MaxPoolSize: Int32 read write;

 

Int32 MaxPoolSize { get; set; }

 

Property MaxPoolSize() As Int32

MoveNext    (declared in BaseObjectPool<TItem>)

Advances the enumerator to the next element of the collection of non-acquired object pool items.

This property is part of the IEnumerator interface implementation.

 

method MoveNext: Boolean

 

Boolean MoveNext()

 

Function MoveNext() As Boolean

NonAcquiredInstancesCount    (declared in BaseObjectPool<TItem>)

Gets the number of pool items that were instantiated but are not currently acquired.

 

property NonAcquiredInstancesCount: Int32 read;

 

Int32 NonAcquiredInstancesCount { get; }

 

ReadOnly Property NonAcquiredInstancesCount() As Int32

ObjectType

Returns a System.Type instance of the type used in this object pool. This is used by the class to create a new instance with Activator. This is equal to TypeOf(<type passed as generic parameter>)

 

property ObjectType: Type read;

 

Type ObjectType { get; }

 

ReadOnly Property ObjectType() As Type

OnCreateInstance  protected

 

method OnCreateInstance: TItem

 

TItem OnCreateInstance()

 

Function OnCreateInstance() As TItem

OnDisposeInstance  protected

 

method OnDisposeInstance(instance: TItem)

 

void OnDisposeInstance(TItem instance)

 

Sub OnDisposeInstance(instance As TItem)

Parameters:

  • instance:

PoolSize    (declared in BaseObjectPool<TItem>)

Gets the current pool size. The value of this property equals the sum of the AcquiredInstancesCount and the NonAcquiredInstancesCount.

 

property PoolSize: Int32 read;

 

Int32 PoolSize { get; }

 

ReadOnly Property PoolSize() As Int32

ReleaseInstance    (declared in BaseObjectPool<TItem>)

Releases an acquired item back into the object pool.

 

method ReleaseInstance(item: TItem)

 

void ReleaseInstance(TItem item)

 

Sub ReleaseInstance(item As TItem)

Parameters:

  • item:

Reset    (declared in BaseObjectPool<TItem>)

Sets the enumerator to its initial position, which is before the first element in the collection of non-acquired object pool items.

This property is part of the IEnumerator interface implementation.

 

method Reset

 

void Reset()

 

Sub Reset()

Resize    (declared in BaseObjectPool<TItem>)

Instantiates the object pool items until there are at least aNewSize non-acquired items in the pool.

If the value of the second parameter is true, this method also sets the MaxPoolSize to aNewSize.

If the value of the second parameter is false and there are more pool items (both acquired and non-acquired) than aNewSize, an exception is raised.

 

method Resize(newSize: Int32; resetMaxPoolSize: Boolean): Int32

 

Int32 Resize(Int32 newSize, Boolean resetMaxPoolSize)

 

Function Resize(newSize As Int32, resetMaxPoolSize As Boolean) As Int32

Parameters:

  • newSize:
  • resetMaxPoolSize:

WaitTimeOut    (declared in BaseObjectPool<TItem>)

Gets or sets the timeout in milliseconds for acquiring new pool items. This is the time that the pool will wait to acquire a new instance before throwing a timeout exception when the Behavior is set to PoolBehavior.Wait.

If the value is -1, the pool will wait indefinitely.

 

property WaitTimeOut: Int32 read write;

 

Int32 WaitTimeOut { get; set; }

 

Property WaitTimeOut() As Int32

 

AcquiredInstancesCount    (declared in BaseObjectPool<TItem>)

Gets the count of the currently acquired object pool elements.

 

property AcquiredInstancesCount: Int32 read;

 

Int32 AcquiredInstancesCount { get; }

 

ReadOnly Property AcquiredInstancesCount() As Int32

Behavior    (declared in BaseObjectPool<TItem>)

Specifies the behavior of the object pool when an item is requested but the pool is empty (i.e. all available elements are acquired).

See the description of the AcquireInstance method for more details about possible Behavior settings.

 

property Behavior: PoolBehavior read write;

 

PoolBehavior Behavior { get; set; }

 

Property Behavior() As PoolBehavior

Current    (declared in BaseObjectPool<TItem>)

Gets the current element in the collection.

This property is a part of the IEnumerator interface implementation.

 

property Current: Object read;

 

Object Current { get; }

 

ReadOnly Property Current() As Object

Instances  protected    (declared in BaseObjectPool<TItem>)

Gets all pooled instances as a linked list.

This property can be used in the BaseObjectPool descendants to fine-tune pooled instances etc.

 

property Instances: LinkedList<TItem> read;

 

LinkedList<TItem> Instances { get; }

 

ReadOnly Property Instances() As LinkedList<TItem>

MaxPoolSize    (declared in BaseObjectPool<TItem>)

Gets the maximum number of items that can be contained in the pool.

-1 means the pool is of unlimited size.

It is not possible to set this property to a positive value less than the AcquiredInstancesCount, doing so will raise an exception. At the same time, it is always possible to set value of this property to -1.

 

property MaxPoolSize: Int32 read write;

 

Int32 MaxPoolSize { get; set; }

 

Property MaxPoolSize() As Int32

NonAcquiredInstancesCount    (declared in BaseObjectPool<TItem>)

Gets the number of pool items that were instantiated but are not currently acquired.

 

property NonAcquiredInstancesCount: Int32 read;

 

Int32 NonAcquiredInstancesCount { get; }

 

ReadOnly Property NonAcquiredInstancesCount() As Int32

ObjectType

Returns a System.Type instance of the type used in this object pool. This is used by the class to create a new instance with Activator. This is equal to TypeOf(<type passed as generic parameter>)

 

property ObjectType: Type read;

 

Type ObjectType { get; }

 

ReadOnly Property ObjectType() As Type

PoolSize    (declared in BaseObjectPool<TItem>)

Gets the current pool size. The value of this property equals the sum of the AcquiredInstancesCount and the NonAcquiredInstancesCount.

 

property PoolSize: Int32 read;

 

Int32 PoolSize { get; }

 

ReadOnly Property PoolSize() As Int32

WaitTimeOut    (declared in BaseObjectPool<TItem>)

Gets or sets the timeout in milliseconds for acquiring new pool items. This is the time that the pool will wait to acquire a new instance before throwing a timeout exception when the Behavior is set to PoolBehavior.Wait.

If the value is -1, the pool will wait indefinitely.

 

property WaitTimeOut: Int32 read write;

 

Int32 WaitTimeOut { get; set; }

 

Property WaitTimeOut() As Int32

 

constructor

 

constructor

 

ObjectPool<TItem>()

 

Sub New()

constructor (PoolBehavior, Int32, Int32, Int32)

 

constructor(behavior: PoolBehavior; initialSize: Int32; maxSize: Int32; timeout: Int32)

 

ObjectPool<TItem>(PoolBehavior behavior, Int32 initialSize, Int32 maxSize, Int32 timeout)

 

Sub New(behavior As PoolBehavior, initialSize As Int32, maxSize As Int32, timeout As Int32)

Parameters:

  • behavior:
  • initialSize:
  • maxSize:
  • timeout:

constructor (PoolBehavior, Int32, Int32)  protected    (declared in BaseObjectPool<TItem>)

 

constructor(behavior: PoolBehavior; maxSize: Int32; timeout: Int32)

 

ObjectPool<TItem>(PoolBehavior behavior, Int32 maxSize, Int32 timeout)

 

Sub New(behavior As PoolBehavior, maxSize As Int32, timeout As Int32)

Parameters:

  • behavior:
  • maxSize:
  • timeout:

AcquireInstance    (declared in BaseObjectPool<TItem>)

Acquires an item from the pool.

If there are non-acquired pool items or pool has an infinite size, the pool item is acquired and returned to the caller. Otherwise, the Behavior property specifies the result of the method call:

  • PoolBehavior.Wait - wait until any pool item becomes available.
  • PoolBehavior.IgnoreAndReturn - wait for no more than WaitTimeOut milliseconds for any pool items. If there still are no pool items available after timeout, null will be returned.
  • PoolBehavior.Raise - wait for no more than WaitTimeOut milliseconds for any pool items. If there still are no pool items available after timeout, an NoFreeObjectsInPoolException is raised.

 

method AcquireInstance: TItem

 

TItem AcquireInstance()

 

Function AcquireInstance() As TItem

Clear    (declared in BaseObjectPool<TItem>)

Clears all items from the pool.

 

method Clear

 

void Clear()

 

Sub Clear()

Dispose    (declared in BaseObjectPool<TItem>)

Releases all pool resources.

The FinalizePool method can be overridden in case some specific cleanup actions are needed.

 

method Dispose

 

void Dispose()

 

Sub Dispose()

DropInstance    (declared in BaseObjectPool<TItem>)

Removes the anItem object from the pool.

 

method DropInstance(item: TItem)

 

void DropInstance(TItem item)

 

Sub DropInstance(item As TItem)

Parameters:

  • item:

ExposeNonAcquiredInstances    (declared in BaseObjectPool<TItem>)

Exposes all non-acquired pool objects using the specified aDelegate.

 

method ExposeNonAcquiredInstances(action: ExposeNonAcquiredInstancesDelegate<TItem>)

 

void ExposeNonAcquiredInstances(ExposeNonAcquiredInstancesDelegate<TItem> action)

 

Sub ExposeNonAcquiredInstances(action As ExposeNonAcquiredInstancesDelegate<TItem>)

Parameters:

  • action:

FinalizePool  protected    (declared in BaseObjectPool<TItem>)

Finalizes the object pool.

This method's implementation is empty in the BaseObjectPool class but can be overriden in derived classes in case some specific cleanup actions are needed.

 

method FinalizePool

 

void FinalizePool()

 

Sub FinalizePool()

GetEnumerator    (declared in BaseObjectPool<TItem>)

Returns an enumerator that iterates through a collection of non-acquired pool objects.

This method is part of the IEnumerable interface implementation.

 

method GetEnumerator: IEnumerator

 

IEnumerator GetEnumerator()

 

Function GetEnumerator() As IEnumerator

MoveNext    (declared in BaseObjectPool<TItem>)

Advances the enumerator to the next element of the collection of non-acquired object pool items.

This property is part of the IEnumerator interface implementation.

 

method MoveNext: Boolean

 

Boolean MoveNext()

 

Function MoveNext() As Boolean

OnCreateInstance  protected

 

method OnCreateInstance: TItem

 

TItem OnCreateInstance()

 

Function OnCreateInstance() As TItem

OnDisposeInstance  protected

 

method OnDisposeInstance(instance: TItem)

 

void OnDisposeInstance(TItem instance)

 

Sub OnDisposeInstance(instance As TItem)

Parameters:

  • instance:

ReleaseInstance    (declared in BaseObjectPool<TItem>)

Releases an acquired item back into the object pool.

 

method ReleaseInstance(item: TItem)

 

void ReleaseInstance(TItem item)

 

Sub ReleaseInstance(item As TItem)

Parameters:

  • item:

Reset    (declared in BaseObjectPool<TItem>)

Sets the enumerator to its initial position, which is before the first element in the collection of non-acquired object pool items.

This property is part of the IEnumerator interface implementation.

 

method Reset

 

void Reset()

 

Sub Reset()

Resize    (declared in BaseObjectPool<TItem>)

Instantiates the object pool items until there are at least aNewSize non-acquired items in the pool.

If the value of the second parameter is true, this method also sets the MaxPoolSize to aNewSize.

If the value of the second parameter is false and there are more pool items (both acquired and non-acquired) than aNewSize, an exception is raised.

 

method Resize(newSize: Int32; resetMaxPoolSize: Boolean): Int32

 

Int32 Resize(Int32 newSize, Boolean resetMaxPoolSize)

 

Function Resize(newSize As Int32, resetMaxPoolSize As Boolean) As Int32

Parameters:

  • newSize:
  • resetMaxPoolSize: