IPoolManager

interface IPoolManager

The memory pool manager, which is used to create new pools of objects.

IPool<T> NewPool<T>(string name, int size, System.Action<T> resetAction)

Creates a new fixed-size memory pool of the specified size.

To use this method, the objects must have a public, parameter-less constructor. If they do not, you should use one of the variants of this method call that require for a factory function.

Type Parameters:
 
  • T – The type of objects to store in the memory pool.
Parameters:
  • name (string) – The user-friendly name of the pool which can be viewed during memory debugging.
  • size (int) – The size of the memory pool.
  • resetAction (System.Action<T>) – An action which is called when the state of an object needs to be reset before reusing it.
Returns:

The memory pool.

IPool<T> NewPool<T>(string name, int size, System.Func<T> factoryFunc, System.Action<T> resetAction)

Creates a new fixed-size memory pool of the specified size.

Type Parameters:
 
  • T – The type of objects to store in the memory pool.
Parameters:
  • name (string) – The user-friendly name of the pool which can be viewed during memory debugging.
  • size (int) – The size of the memory pool.
  • factoryFunc (System.Func<T>) – The factory function which allocates new objects for the pool.
  • resetAction (System.Action<T>) – An action which is called when the state of an object needs to be reset before reusing it.
Returns:

The memory pool.

IPool<T> NewPool<T>(string name, int size, System.Func<T> factoryFunc, System.Action<T> resetAction, System.Action<T> newAction)

Creates a new fixed-size memory pool of the specified size.

Type Parameters:
 
  • T – The type of objects to store in the memory pool.
Parameters:
  • name (string) – The user-friendly name of the pool which can be viewed during memory debugging.
  • size (int) – The size of the memory pool.
  • factoryFunc (System.Func<T>) – The factory function which allocates new objects for the pool.
  • resetAction (System.Action<T>) – An action which is called when the state of an object needs to be reset before reusing it.
  • newAction (System.Action<T>) – An action which is called before an object is given out for the first time.
Returns:

The memory pool.

IPool<T> NewScalingPool<T>(string name, int increment, System.Action<T> resetAction)

Creates a new scaling memory pool which can allocate and de-allocate blocks of objects as needed. This ensures that allocations of memory happen less frequently that they would otherwise for normal allocation and garbage collection.

To use this method, the objects must have a public, parameter-less constructor. If they do not, you should use one of the variants of this method call that require for a factory function.

Type Parameters:
 
  • T – The type of objects to store in the memory pool.
Parameters:
  • name (string) – The user-friendly name of the pool which can be viewed during memory debugging.
  • increment (int) – The size by which to increment the memory pool when more objects are needed, and the size by which to decrement the pool when less objects are needed.
  • resetAction (System.Action<T>) – An action which is called when the state of an object needs to be reset before reusing it.
Returns:

The memory pool.

IPool<T> NewScalingPool<T>(string name, int increment, System.Func<T> factoryFunc, System.Action<T> resetAction)

Creates a new scaling memory pool which can allocate and de-allocate blocks of objects as needed. This ensures that allocations of memory happen less frequently that they would otherwise for normal allocation and garbage collection.

To use this method, the objects must have a public, parameter-less constructor. If they do not, you should use one of the variants of this method call that require for a factory function.

Type Parameters:
 
  • T – The type of objects to store in the memory pool.
Parameters:
  • name (string) – The user-friendly name of the pool which can be viewed during memory debugging.
  • increment (int) – The size by which to increment the memory pool when more objects are needed, and the size by which to decrement the pool when less objects are needed.
  • factoryFunc (System.Func<T>) – The factory function which allocates new objects for the pool.
  • resetAction (System.Action<T>) – An action which is called when the state of an object needs to be reset before reusing it.
Returns:

The memory pool.

IPool<T> NewScalingPool<T>(string name, int increment, System.Func<T> factoryFunc, System.Action<T> resetAction, System.Action<T> newAction)

Creates a new scaling memory pool which can allocate and de-allocate blocks of objects as needed. This ensures that allocations of memory happen less frequently that they would otherwise for normal allocation and garbage collection.

To use this method, the objects must have a public, parameter-less constructor. If they do not, you should use one of the variants of this method call that require for a factory function.

Type Parameters:
 
  • T – The type of objects to store in the memory pool.
Parameters:
  • name (string) – The user-friendly name of the pool which can be viewed during memory debugging.
  • increment (int) – The size by which to increment the memory pool when more objects are needed, and the size by which to decrement the pool when less objects are needed.
  • factoryFunc (System.Func<T>) – The factory function which allocates new objects for the pool.
  • resetAction (System.Action<T>) – An action which is called when the state of an object needs to be reset before reusing it.
  • newAction (System.Action<T>) – An action which is called before an object is given out for the first time.
Returns:

The memory pool.

Protogame.IPool<T[]> NewArrayPool<T>(string name, int size, int arraySize, System.Action<T[]> resetAction)
Type Parameters:
 
  • T
Parameters:
  • name (string) –
  • size (int) –
  • arraySize (int) –
  • resetAction (System.Action<T[]>) –
Protogame.IPool<T[]> NewScalingArrayPool<T>(string name, int increment, int arraySize, System.Action<T[]> resetAction)
Type Parameters:
 
  • T
Parameters:
  • name (string) –
  • increment (int) –
  • arraySize (int) –
  • resetAction (System.Action<T[]>) –