public void Free() { if ( m_Enumerator != null ) { m_InstancePool.Enqueue( this ); m_Enumerator.Free(); m_Enumerator = null; --m_Depth; } }
public static PooledEnumerable Instantiate( IPooledEnumerator etor ) { ++m_Depth; if ( m_Depth >= 5 ) Console.WriteLine( "Warning: Make sure to call .Free() on pooled enumerables." ); PooledEnumerable e; if ( m_InstancePool.Count > 0 ) { e = m_InstancePool.Dequeue(); e.m_Enumerator = etor; } else { e = new PooledEnumerable( etor ); } etor.Enumerable = e; return e; }
public static PooledEnumerable Instantiate( IPooledEnumerator etor ) { ++m_Depth; if ( m_Depth >= 5 ) log.WarnFormat("Make sure to call .Free() on pooled enumerables."); PooledEnumerable e; if ( m_InstancePool.Count > 0 ) { e = (PooledEnumerable)m_InstancePool.Dequeue(); e.m_Enumerator = etor; } else { e = new PooledEnumerable( etor ); } etor.Enumerable = e; return e; }
private PooledEnumerable( IPooledEnumerator etor ) { m_Enumerator = etor; }
public void Free() { if (m_Enumerator != null) { // reset this.Status = PooledEnumerable.status.normal; m_InstancePool.Enqueue(this); m_Enumerator.Free(); m_Enumerator = null; --m_Depth; } }
public static PooledEnumerable Instantiate(IPooledEnumerator etor) { ++m_Depth; // track current depth if (m_Depth > m_HighWaterMark) // track max depth m_HighWaterMark = m_Depth; if (m_Depth >= 5) Console.WriteLine("PooledEnumerable: Depth = {0}, High Water Mark = {1}", m_Depth, m_HighWaterMark); PooledEnumerable e; if (m_InstancePool.Count > 0) { e = (PooledEnumerable)m_InstancePool.Dequeue(); e.m_Enumerator = etor; if (e != null && e.Status != PooledEnumerable.status.normal && e.Status != PooledEnumerable.status.derived_moveNext) { // always happens. Back to the drawing board. // string message = String.Format("PooledEnumerable.Instantiate() called after the derived class was: {0}", e.Status.ToString()); // Console.WriteLine(message); } if (etor == null) { // TEST string message = String.Format("PooledEnumerable.Instantiate() etor starting out null"); Console.WriteLine(message); } } else { e = new PooledEnumerable(etor); } etor.Enumerable = e; // reset e.Status = PooledEnumerable.status.normal; return e; }