using System; using System.Collections.Generic; using System.Text; namespace OpenTK { class ObjectPool where T : IPoolable, new() { Queue pool = new Queue(); public ObjectPool() { } public T Acquire() { T item; if (pool.Count > 0) { item = pool.Dequeue(); item.OnAcquire(); } else { item = new T(); item.Owner = this; item.OnAcquire(); } return item; } public void Release(T item) { if (item == null) throw new ArgumentNullException("item"); item.OnRelease(); pool.Enqueue(item); } } }