/// <summary> /// Creates a new pool of objects with a given size. /// </summary> /// <param name="sizeOfPool">The number of objects within the pool.</param> public ObjectPool(int sizeOfPool, bool grow = false, bool instantiatePolicy = true) { this._sizeOfPool = sizeOfPool; this._pool = new Queue <T>(); this._grow = grow; this._isInitialized = false; if (instantiatePolicy) { this._objectLoadPolicy = new P(); } }
/// <summary> /// Initializes the pool and it's load policy! /// </summary> public virtual void Initialize(IObjectLoadPolicy <T> policy = null, params object[] args) { if (policy != null) { this._objectLoadPolicy = policy; } if (this._objectLoadPolicy != null) { if (!this._objectLoadPolicy.IsCreated()) { this._objectLoadPolicy.Create(args); } } this._isInitialized = true; }