/// <summary> /// Initializes the pool. /// </summary> public void Initialize() { if (pool != null) return; this.pool = new ExpandingPool<WeakReference>(16, 64, () => new WeakReference(null)); }
/// <summary> /// Initializes a new instance of the <see cref="CursorTrackerTouchCollection"/> class. /// </summary> /// <param name="view"></param> public CursorTrackerTouchCollection(PresentationFoundationView view) { Contract.Require(view, nameof(view)); pool = new ExpandingPool <CursorTracker.Touch>(5, () => CursorTracker.ForTouch(view), (tracker) => tracker.OnReleaseIntoPool()); active = new Dictionary <Int64, CursorTracker.Touch>(5); }
public void PooledObjectScope_ScopeRetrievesAndReleasesObject() { var pool = new ExpandingPool<PoolableDataObject>(1); using (var scope = pool.RetrieveScoped()) { TheResultingValue(pool.Capacity).ShouldBe(1); TheResultingValue(pool.Count).ShouldBe(1); scope.Object.Data = "Hello, world!"; } TheResultingValue(pool.Capacity).ShouldBe(1); TheResultingValue(pool.Count).ShouldBe(0); }
public void PooledObjectScope_ScopeRetrievesAndReleasesObject() { var pool = new ExpandingPool <PoolableDataObject>(1); using (var scope = pool.RetrieveScoped()) { TheResultingValue(pool.Capacity).ShouldBe(1); TheResultingValue(pool.Count).ShouldBe(1); scope.Object.Data = "Hello, world!"; } TheResultingValue(pool.Capacity).ShouldBe(1); TheResultingValue(pool.Count).ShouldBe(0); }