本文整理汇总了C#中ObjectPool.Next方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectPool.Next方法的具体用法?C# ObjectPool.Next怎么用?C# ObjectPool.Next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectPool
的用法示例。
在下文中一共展示了ObjectPool.Next方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NoNewObjectsAllocatedWhenCapacityIsNotExceeded
public void NoNewObjectsAllocatedWhenCapacityIsNotExceeded()
{
ObjectPool<ObjectPoolTestObject> pool = new ObjectPool<ObjectPoolTestObject>(() => { return new ObjectPoolTestObject(); }, 2);
var foo = pool.Next();
var bar = pool.Next();
Assert.AreEqual(2, ObjectPoolTestObject.ConstructorCalled);
}
示例2: ActiveCountIncrementsWithEachCallToNext
public void ActiveCountIncrementsWithEachCallToNext()
{
ObjectPool<ObjectPoolTestObject> pool = new ObjectPool<ObjectPoolTestObject>(() => { return new ObjectPoolTestObject(); }, 2);
var foo = pool.Next();
Assert.AreEqual(1, pool.ActiveCount);
var bar = pool.Next();
Assert.AreEqual(2, pool.ActiveCount);
}
示例3: ReturningAnObjectTwiceCausesActiveCountToOnlyDecrementOnce
public void ReturningAnObjectTwiceCausesActiveCountToOnlyDecrementOnce()
{
ObjectPool<ObjectPoolTestObject> pool = new ObjectPool<ObjectPoolTestObject>(() => { return new ObjectPoolTestObject(); }, 2);
var foo = pool.Next();
var bar = pool.Next();
pool.Return(bar);
pool.Return(bar);
Assert.AreEqual(1, pool.ActiveCount);
}
示例4: NoNewObjectsAllocatedAndNullIsReturnedByNextWhenAutoGrowIsFalse
public void NoNewObjectsAllocatedAndNullIsReturnedByNextWhenAutoGrowIsFalse()
{
ObjectPool<ObjectPoolTestObject> pool = new ObjectPool<ObjectPoolTestObject>(() => { return new ObjectPoolTestObject(); }, 2);
pool.AutoGrow = false;
var foo = pool.Next();
var bar = pool.Next();
var baz = pool.Next();
Assert.AreEqual(2, ObjectPoolTestObject.ConstructorCalled);
Assert.IsNull(baz);
}
示例5: AutoGrowFactorIndicatesTheNumberOfNewObjectsAllocatedByAnAutoGrow
public void AutoGrowFactorIndicatesTheNumberOfNewObjectsAllocatedByAnAutoGrow()
{
ObjectPool<ObjectPoolTestObject> pool = new ObjectPool<ObjectPoolTestObject>(() => { return new ObjectPoolTestObject(); }, 2);
pool.AutoGrow = true;
pool.AutoGrowFactor = 2;
var foo = pool.Next();
var bar = pool.Next();
var baz = pool.Next();
Assert.AreEqual(4, ObjectPoolTestObject.ConstructorCalled);
Assert.AreEqual(4, pool.Capactiy);
}
示例6: ReturningObjectCausesActiveCountToDecrement
public void ReturningObjectCausesActiveCountToDecrement()
{
ObjectPool<ObjectPoolTestObject> pool = new ObjectPool<ObjectPoolTestObject>(() => { return new ObjectPoolTestObject(); }, 2);
var foo = pool.Next();
pool.Return(foo);
Assert.AreEqual(0, pool.ActiveCount);
}