Click or drag to resize

SerialisableObjectPoolT Class

[This is preliminary documentation and is subject to change.]

A serialisable, generic implementation of an object pool, that allows for recycling and reuse of objects of type T.
Inheritance Hierarchy

Namespace:  Umbrace.Unity.PurePool
Assembly:  Umbrace.Unity.PurePool (in Umbrace.Unity.PurePool.dll) Version: 0.0.0.0 (1.0.0.0)
Syntax
C#
[SerializableAttribute]
public abstract class SerialisableObjectPool<T> : ISerializationCallbackReceiver, 
	IObjectPool<T>, IObjectPool

Type Parameters

T
The type of object being pooled.

The SerialisableObjectPoolT type exposes the following members.

Constructors
  NameDescription
Protected methodSerialisableObjectPoolT
Initialises a new instance of the SerialisableObjectPoolT class.
Top
Properties
  NameDescription
Public propertyCanAcquire

Gets a value indicating whether an instance can be acquired from the pool.

An instance can be acquired when the pool contains at least one instance, or when InstantiateWhenEmpty is .

Public propertyCount
Gets the number of objects currently contained by the pool.
Public propertyInitialSize
Gets or sets the initial size of the pool. Cannot be set once the pool has been initialised.
Public propertyInstantiateWhenEmpty
Gets or sets a value indicating whether to instantiate a new object when the pool is empty, and an attempt is made to acquire from the pool.
Public propertyIsEmpty
Gets a value indicating whether the pool is empty and contains no objects.
Public propertyIsFull
Gets a value indicating whether the pool is full, and cannot contain any more objects.
Public propertyIsInitialised
Gets a value indicating whether the pool has been initialised.
Public propertyItems
Gets a list of items currently contained by the pool.
Public propertyLogMessages
Gets or sets the level of log messaging that the pool will output.
Public propertyMaximumSize
Gets or sets the maximum size of the pool, which is the maximum number of objects it can contain.
Public propertyRecordStatistics
Gets or sets a value indicating whether to record pool statistics.
Protected propertyRefillPoolOnReinitialise
Gets a value indiciating whether to refill the pool with new objects after the pool is reinitialised, as happens from deserialisation.
Public propertyStatistics
Gets an object containing general operational statistics about the pool.
Top
Methods
  NameDescription
Public methodAcquire
Acquires an object from the pool.
Public methodClear
Clears the pool, emptying it of all pooled objects.
Public methodContains
Determines whether an instance is in the pool.
Public methodEquals (Inherited from Object.)
Public methodFill
Fills the pool, populating it with pooled objects until it reaches the maximum pool size.
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetItems
Protected methodGetObjectFactory
Gets a function used to create new instances of the pooled type. By default, this method uses the public parameterless constructor of type T. This method should be overridden in a subclass if different behaviour is required.
Public methodGetType (Inherited from Object.)
Public methodInitialise
Initialises the pool, populating it with objects and making it ready for use.
Protected methodInitialise(Boolean)
Initialises the pool, making it ready for use, and optionally populating it with objects.
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodOnAfterDeserialize
Performs actions after the object has been deserialised.
Protected methodOnBeforeSerialize
Performs actions prior to the object being serialised.
Protected methodOnCanAcquireChanged
Raises the CanAcquireChanged event.
Protected methodOnCountChanged
Raises the CountChanged event.
Protected methodOnInitialised
Raises the Initialised event.
Protected methodOnObjectAcquired
Raises the ObjectAcquired event.
Protected methodOnObjectDestroyed
Raises the ObjectDestroyed event.
Protected methodOnObjectInstantiated
Raises the ObjectInstantiated event.
Protected methodOnObjectReleased
Raises the ObjectReleased event.
Public methodRelease
Releases an object back to the pool.
Protected methodReleaseInternal
Releases an object back to the pool.
Public methodRemove
Removes the specified instance from the pool.
Public methodSetSize
Sets the number of objects contained by the pool, either destroying excess pooled objects, or instantiating new ones.
Public methodToString (Inherited from Object.)
Public methodTryAcquire
Acquires an object from the pool.
Top
Events
  NameDescription
Public eventCanAcquireChanged
Occurs when the value of CanAcquire changes.
Public eventCountChanged
Occurs when Count changes.
Public eventInitialised
Occurs when the pool is initialised.
Public eventObjectAcquired
Occurs when an object is acquired from the pool.
Public eventObjectDestroyed
Occurs when an object is destroyed.
Public eventObjectInstantiated
Occurs when a new object is instantiated.
Public eventObjectReleased
Occurs when an object is released back to the pool.
Top
Fields
  NameDescription
Public fieldStatic memberDefaultInitialSize
The default initial size of newly-created pools.
Public fieldStatic memberDefaultMaximumPoolSize
The default maximum size of newly-created pools.
Top
Remarks

By virtue of being serialisable, SerialisableObjectPoolT can survive an assembly reload caused by live recompilation inside of the Unity editor. However, to ensure Unity is able to serialise fields containing pools, you should subclass SerialisableObjectPoolT by creating a new, non-generic, class derived from it.

SerialisableObjectPoolT achieves this by serialising the number of instances of the object that were contained in the pool, and then recreating them after deserialisation. In other cases, it's possible to let Unity serialise the objects contained in the pool, and simply add them back into the pool after deserialisation.

To use the SerialisableObjectPoolT, derive a new, non-generic, class from it and override the GetObjectFactory method. This method is responsible for providing an object factory that can create new instances of the desired object. Initialise a new instance of the derived class using the constructor, and then set the properties to appropriate values. Once all properties have been set, invoke the Initialise method. A pool cannot be used without being initialised in this way.

See Also