Class SimpleListManagedPool
A System.Object SimpleList<T> backed pool implementation.
Inheritance
Implements
Namespace: GDX.Collections.Pooling
Syntax
public sealed class SimpleListManagedPool : IManagedPool
Constructors
| Improve this Doc View SourceSimpleListManagedPool(Object, Func<SimpleListManagedPool, Object>, Int32, Int32, Object, Boolean, Boolean, Boolean, Boolean)
Create a SimpleListManagedPool.
Declaration
public SimpleListManagedPool(object baseObject, Func<SimpleListManagedPool, object> createItemFunc, int minimumObjects = 10, int maximumObjects = 50, object containerObject = null, bool prewarmPool = true, bool allowCreateMore = true, bool allowReuseWhenCapped = false, bool allowManagedTearDown = false)
Parameters
Type | Name | Description |
---|---|---|
System.Object | baseObject | The object which going to be cloned. |
System.Func<SimpleListManagedPool, System.Object> | createItemFunc | The function used to create new items for the pool. |
System.Int32 | minimumObjects | The minimum number of objects to be managed by the pool. |
System.Int32 | maximumObjects | The maximum number of objects to be managed by the pool. |
System.Object | containerObject | A reference to an object which should be used as the container for created items. |
System.Boolean | prewarmPool | Should this pool create its items during the constructor? |
System.Boolean | allowCreateMore | Can more items be created as needed when starved for items? |
System.Boolean | allowReuseWhenCapped | Should we reuse oldest items when starving for items? |
System.Boolean | allowManagedTearDown | Does the pool allow a managed tear down event call? |
Fields
| Improve this Doc View SourceBaseObject
The object which the pool is based off of, used as a model when creating new items.
Declaration
public readonly object BaseObject
Field Value
Type | Description |
---|---|
System.Object |
ContainerObject
The object which serves as a container for all objects of the pool.
Declaration
public readonly object ContainerObject
Field Value
Type | Description |
---|---|
System.Object |
Remarks
Used more by implementations of pools, then this base class.
destroyedItem
An event
invoked when an item is destroyed by the SimpleListManagedPool.
Declaration
public Action<object> destroyedItem
Field Value
Type | Description |
---|---|
System.Action<System.Object> |
Flags
A BitArray8 used to store pool based flags, as well as provide additional spots for implementations.
Declaration
public BitArray8 Flags
Field Value
Type | Description |
---|---|
BitArray8 |
Remarks
Index 0-3 (GDX.Collections.Pooling.SimpleListManagedPool.k_AllowCreateMoreFlag, GDX.Collections.Pooling.SimpleListManagedPool.k_AllowManagedTeardownFlag, GDX.Collections.Pooling.SimpleListManagedPool.k_AllowReuseFlag, and GDX.Collections.Pooling.SimpleListManagedPool.k_PrewarmPoolFlag) are used by the SimpleListManagedPool itself, leaving 4-7 for additional use.
InCachedCount
A cached count of the number of items contained in InItems.
Declaration
public int InCachedCount
Field Value
Type | Description |
---|---|
System.Int32 |
InItems
A collection of items that are currently contained in the pool for use when spawning items upon request.
Declaration
public SimpleList<object> InItems
Field Value
Type | Description |
---|---|
SimpleList<System.Object> |
OutCachedCount
A cached count of the number of items contained in GDX.Collections.Pooling.SimpleListManagedPool.m_OutItems.
Declaration
public int OutCachedCount
Field Value
Type | Description |
---|---|
System.Int32 |
returnedItem
An event
invoked when an item is returned to the SimpleListManagedPool.
Declaration
public Action<SimpleListManagedPool, object> returnedItem
Field Value
Type | Description |
---|---|
System.Action<SimpleListManagedPool, System.Object> |
spawnedItem
An event
invoked when an item is spawned from the SimpleListManagedPool.
Declaration
public Action<SimpleListManagedPool, object> spawnedItem
Field Value
Type | Description |
---|---|
System.Action<SimpleListManagedPool, System.Object> |
tearingDown
An event
invoked when a pool is tearing down, before the items are pooled.
Declaration
public Action<SimpleListManagedPool> tearingDown
Field Value
Type | Description |
---|---|
System.Action<SimpleListManagedPool> |
Methods
| Improve this Doc View SourceCreateItem()
Create a pooled item and add it to the IManagedPool.
Declaration
public void CreateItem()
Finalize()
The SimpleListManagedPool destructor which unregisters itself from ManagedPools.
Declaration
protected void Finalize()
ForceRemove(Object)
Remove an item
from an IManagedPool immediately, removing it from tracking and
not calling any actions on it.
Declaration
public void ForceRemove(object item)
Parameters
Type | Name | Description |
---|---|---|
System.Object | item | The target System.Object to attempt to remove. |
Get(Boolean)
Get the next available item from an IManagedPool.
Declaration
public object Get(bool triggerOnSpawnedFromPool = true)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | triggerOnSpawnedFromPool |
Returns
Type | Description |
---|---|
System.Object | An item if available, otherwise null. |
GetBaseObject()
Return the System.Object which the pool is built from.
Declaration
public object GetBaseObject()
Returns
Type | Description |
---|---|
System.Object | The System.Object the IManagedPool is modelled around. |
GetKey()
Get the unique identifier for the IManagedPool.
Declaration
public uint GetKey()
Returns
Type | Description |
---|---|
System.UInt32 | A unique identifier. |
HasMinimumPooledItems()
Does the IManagedPool contain the minimum number of items.
Declaration
public bool HasMinimumPooledItems()
Returns
Type | Description |
---|---|
System.Boolean | true/false if enough items are found contained in the IManagedPool. |
IsAllowedManagedTearDown()
Should theIManagedPool destroy itself when ManagedPools requests a tear down?
Declaration
public bool IsAllowedManagedTearDown()
Returns
Type | Description |
---|---|
System.Boolean | true/false if flagged to allow for managed tear down / clean up. |
IsManaged(Object)
Is the item
managed by this IManagedPool?
Declaration
public bool IsManaged(object item)
Parameters
Type | Name | Description |
---|---|---|
System.Object | item | The System.Object to evaluate. |
Returns
Type | Description |
---|---|
System.Boolean | true/false if the |
IsPooled(Object)
Is the provided item
found in the IManagedPool's internal available pool of
objects?
Declaration
public bool IsPooled(object item)
Parameters
Type | Name | Description |
---|---|---|
System.Object | item | The |
Returns
Type | Description |
---|---|
System.Boolean |
Return(Object)
Return the item
to the IManagedPool's internal collection.
Declaration
public void Return(object item)
Parameters
Type | Name | Description |
---|---|---|
System.Object | item | The |
ReturnAll(Boolean)
Return all spawned System.Objects to the IManagedPool.
Declaration
public void ReturnAll(bool shouldShrink = true)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | shouldShrink | Should the IManagedPool be shrunk to its original maximum size? |
Remarks
Shrinking the pools helps with pools that have grown out of necessity past their maximum size
TearDown()
Destroy all System.Objects associated with the IManagedPool.
Declaration
public void TearDown()