diff --git a/Implab/Components/ExecutionState.cs b/Implab/Components/ExecutionState.cs --- a/Implab/Components/ExecutionState.cs +++ b/Implab/Components/ExecutionState.cs @@ -1,4 +1,5 @@ namespace Implab.Components { + public enum ExecutionState { Uninitialized, Initial, diff --git a/Implab/Components/ObjectPool.cs b/Implab/Components/ObjectPool.cs --- a/Implab/Components/ObjectPool.cs +++ b/Implab/Components/ObjectPool.cs @@ -4,18 +4,17 @@ using System.Threading; namespace Implab.Components { /// - /// Базовый класс для создания пулов объектов. + /// The base class for creating object pools. /// /// - /// Пул объектов позволяет многократно использовать один и тотже объект, - /// что актуально для объектов, создание которых требует существенных ресурсов. - /// Пул объектов использует слабые ссылки, чтобы не препятствовать освобождению - /// ресурсов и создает новые объекты при необходимости. + /// The objects pool is offers frequently requested objects to be reused, this gives + /// a gool speed improvement for the 'heavy' objects. To avoid memory overhead the pool uses + /// weak references allowing CG to do it's work. If there are no free objects in the pool + /// they are created on demand. /// - /// Наследники должны реализовывать метод для создания - /// новых экземпляров. + /// Implementors need to defined a method /// - /// Пул поддерживает обращения сразу из нескольких потоков. + /// The instances of this class are thred-safe. /// public abstract class ObjectPool where T : class { readonly AsyncQueue m_queue = new AsyncQueue(); @@ -32,11 +31,22 @@ namespace Implab.Components { m_size = size; } + /// + /// Creates the instance if there are no free ones in the pool. + /// + /// The new instance. protected abstract T CreateInstance(); + /// + /// Cleanups the instance. + /// + /// The instance to cleanup and prepare it for the next use. protected virtual void CleanupInstance(T instance) { } + /// + /// Allocate free instance from the pool or reates a new one. + /// public T Allocate() { WeakReference reference; while (m_queue.TryDequeue(out reference)) { @@ -49,6 +59,11 @@ namespace Implab.Components { return CreateInstance(); } + /// + /// Release the specified instance and returns it to the pool of free instances. + /// + /// The instance to return to the pool. + /// Before the instance is returned to the pool the is called. public void Release(T instance) { if (m_count < m_size && instance != null) { Interlocked.Increment(ref m_count);