Show / Hide Table of Contents

    Class ObjectPool<T>

    Object pool which can store instances so that they can be reused This is useful for objects like GameObjects or Meshes where the creation and destruction drops the performance This should definitely be used for meshes since they are not automatically cleaned up by the garbage collector

    Inheritance
    Object
    ObjectPool<T>
    Namespace: i5.Toolkit.Core.Utilities
    Assembly: cs.temp.dll.dll
    Syntax
    public static class ObjectPool<T>
    Type Parameters
    Name Description
    T

    The object type which should be stored in the pool

    Methods

    ClearPool(Action<T>)

    Clears the default pool by removing every instance in the queue Performs the given destroyAction on each instance to destroy it You probably want to use Destroy() inside the destroyAction

    Declaration
    public static void ClearPool(Action<T> destroyAction = null)
    Parameters
    Type Name Description
    Action<T> destroyAction

    ClearPool(Int32, Action<T>)

    Clears the pool by removing every instance in the queue Performs the given destroyAction on each instance to destroy it You probably want to use Destroy() inside the destroyAction

    Declaration
    public static void ClearPool(int poolId, Action<T> destroyAction = null)
    Parameters
    Type Name Description
    Int32 poolId

    The id of the pool which should be cleared

    Action<T> destroyAction

    The action which should be performed to destroy on object

    CountPools()

    Declaration
    public static int CountPools()
    Returns
    Type Description
    Int32

    CreateNewPool()

    Opens a new pool and returns the id of the pool

    Declaration
    public static int CreateNewPool()
    Returns
    Type Description
    Int32

    The id of the created pool

    CreateNewPool(Int32)

    Opens a new pool and returns the id of the pool

    Declaration
    public static int CreateNewPool(int capacity)
    Parameters
    Type Name Description
    Int32 capacity

    Define a (soft) capacity of the pool for which memory is allocated in advance

    Returns
    Type Description
    Int32

    The id of the created pool

    ReleaseResource(T)

    Returns the resource to the default pool so that it can be requested again This should return all control over this object back to the pool

    Declaration
    public static void ReleaseResource(T resource)
    Parameters
    Type Name Description
    T resource

    The resource which is returned to the pool

    ReleaseResource(Int32, T)

    Returns the resource to the pool so that it can be requested again This should return all control over this object back to the pool

    Declaration
    public static void ReleaseResource(int poolId, T resource)
    Parameters
    Type Name Description
    Int32 poolId

    The id of the pool

    T resource

    The resource which is returned to the pool

    RemovePool(Int32, Action<T>)

    First cleans and then removes the pool with the given id

    Declaration
    public static void RemovePool(int poolId, Action<T> destroyAction = null)
    Parameters
    Type Name Description
    Int32 poolId
    Action<T> destroyAction

    RequestResource(Func<T>)

    Requests a resource from the default pool If no resource is left, the code in the creationFactory function will be executed to create a new object The creationFactory should probably use Unity's Instantiate method

    Declaration
    public static T RequestResource(Func<T> creationFactory)
    Parameters
    Type Name Description
    Func<T> creationFactory

    Function which should create a new instance of the pooled object

    Returns
    Type Description
    T

    An instance of the object from the pool

    RequestResource(Int32, Func<T>)

    Requests a resource from the pool If no resource is left, the code in the creationFactory function will be executed to create a new object The creationFactory should probably use Unity's Instantiate method

    Declaration
    public static T RequestResource(int poolId, Func<T> creationFactory)
    Parameters
    Type Name Description
    Int32 poolId
    Func<T> creationFactory

    Function which should create a new instance of the pooled object

    Returns
    Type Description
    T

    An instance of the object from the pool

    Back to top i5 Toolkit Documentation