本文整理汇总了C#中ObjectPool.Return方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectPool.Return方法的具体用法?C# ObjectPool.Return怎么用?C# ObjectPool.Return使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectPool
的用法示例。
在下文中一共展示了ObjectPool.Return方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: DataService
public DataService(ITracer tracer, IPqlEngineHostProcess process, string instanceName, int maxEngineConcurrency, IDataEngineCache dataEngineCache)
{
if (tracer == null)
{
throw new ArgumentNullException("tracer");
}
if (process == null)
{
throw new ArgumentNullException("process");
}
if (string.IsNullOrEmpty(instanceName))
{
throw new ArgumentNullException("instanceName");
}
if (maxEngineConcurrency <= 0 || maxEngineConcurrency > 10000)
{
throw new ArgumentOutOfRangeException("maxEngineConcurrency", maxEngineConcurrency, "Invalid value");
}
m_protocolVersion = "default";
m_tracer = tracer;
m_cancellationTokenSource = new CancellationTokenSource();
m_process = process;
m_instanceName = instanceName;
m_maxEngineConcurrency = maxEngineConcurrency;
m_counters = new RawDataWriterPerfCounters(instanceName);
m_requestManagers = new RequestProcessingManager[maxEngineConcurrency];
// request processing managers will not be dynamically created,
// this is to explicitly limit concurrency regardless of service infrastructure settings
m_requestManagersPool = new ObjectPool<RequestProcessingManager>(m_maxEngineConcurrency, null);
for (var i = 0; i < m_requestManagersPool.Capacity; i++)
{
m_requestManagers[i] = new RequestProcessingManager(m_tracer, m_process, m_counters);
m_requestManagersPool.Return(m_requestManagers[i]);
}
m_enginesCache = dataEngineCache ?? new DataEngineCache(m_tracer, m_instanceName, m_maxEngineConcurrency);
}
示例3: 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);
}
示例4: QueryParser
/// <summary>
/// Ctr.
/// </summary>
public QueryParser(DataContainerDescriptor containerDescriptor, int maxConcurrency)
{
if (containerDescriptor == null)
{
throw new ArgumentNullException("containerDescriptor");
}
m_parsers = new ObjectPool<Irony.Parsing.Parser>(maxConcurrency, null);
for (var i = 0; i < maxConcurrency; i++)
{
m_parsers.Return(new Irony.Parsing.Parser(LangData, PqlNonTerminal));
}
m_containerDescriptor = containerDescriptor;
m_preprocessor = new QueryPreprocessor(containerDescriptor);
// these predefined instances of ParseTreeNode are substituted when parsing "select * from .." statement,
// in order to avoid allocating them every time
m_simpleFieldAccessorNodes = new Dictionary<int, ParseTreeNode>();
foreach (var field in m_containerDescriptor.EnumerateFields())
{
// generate columnItem -> columnSource -> Id -> id_simple hierarchy, exactly same structure as it comes out of grammar-based parser
var idNode = new ParseTreeNode(new NonTerminal("Id"), new SourceSpan());
idNode.ChildNodes.Add(new ParseTreeNode(new Token(new Terminal("id_simple"), new SourceLocation(), field.Name, field.Name)));
var columnSourceNode = new ParseTreeNode(new NonTerminal("columnSource"), new SourceSpan());
columnSourceNode.ChildNodes.Add(idNode);
var columnItemNode = new ParseTreeNode(new NonTerminal("columnItem"), new SourceSpan());
columnItemNode.ChildNodes.Add(columnSourceNode);
m_simpleFieldAccessorNodes.Add(field.FieldId, columnItemNode);
}
}