mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-19 01:31:17 -10:00
Adding reference source for System.Data System.Data.DataSetExtensions System.Data.Entity System.Data.Entity.Design System.Data.Linq System.Data.SqlXml System.ServiceModel System.ServiceModel.Activation System.ServiceModel.Activities System.ServiceModel.Channels System.ServiceModel.Discovery System.ServiceModel.Internals System.ServiceModel.Routing System.ServiceModel.WasHosting System.ServiceModel.Web System.Web System.Web.ApplicationServices System.Web.DynamicData System.Web.Entity System.Web.Entity.Design System.Web.Extensions System.Web.Mobile System.Web.Routing System.Web.Services System.Xml System.Xml.Linq
73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
//------------------------------------------------------------
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
//------------------------------------------------------------
|
|
namespace System.ServiceModel.Channels
|
|
{
|
|
using System.Runtime;
|
|
|
|
class ConnectionBufferPool : QueuedObjectPool<byte[]>
|
|
{
|
|
const int SingleBatchSize = 128 * 1024;
|
|
const int MaxBatchCount = 16;
|
|
const int MaxFreeCountFactor = 4;
|
|
int bufferSize;
|
|
|
|
public ConnectionBufferPool(int bufferSize)
|
|
{
|
|
int batchCount = ComputeBatchCount(bufferSize);
|
|
this.Initialize(bufferSize, batchCount, batchCount * MaxFreeCountFactor);
|
|
}
|
|
|
|
public ConnectionBufferPool(int bufferSize, int maxFreeCount)
|
|
{
|
|
this.Initialize(bufferSize, ComputeBatchCount(bufferSize), maxFreeCount);
|
|
}
|
|
|
|
void Initialize(int bufferSize, int batchCount, int maxFreeCount)
|
|
{
|
|
Fx.Assert(bufferSize >= 0, "bufferSize must be non-negative");
|
|
Fx.Assert(batchCount > 0, "batchCount must be positive");
|
|
Fx.Assert(maxFreeCount >= 0, "maxFreeCount must be non-negative");
|
|
|
|
this.bufferSize = bufferSize;
|
|
if (maxFreeCount < batchCount)
|
|
{
|
|
maxFreeCount = batchCount;
|
|
}
|
|
base.Initialize(batchCount, maxFreeCount);
|
|
}
|
|
|
|
public int BufferSize
|
|
{
|
|
get
|
|
{
|
|
return this.bufferSize;
|
|
}
|
|
}
|
|
|
|
protected override byte[] Create()
|
|
{
|
|
return DiagnosticUtility.Utility.AllocateByteArray(this.bufferSize);
|
|
}
|
|
|
|
static int ComputeBatchCount(int bufferSize)
|
|
{
|
|
int batchCount;
|
|
if (bufferSize != 0)
|
|
{
|
|
batchCount = (SingleBatchSize + bufferSize - 1) / bufferSize;
|
|
if (batchCount > MaxBatchCount)
|
|
{
|
|
batchCount = MaxBatchCount;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// It's OK to have zero bufferSize
|
|
batchCount = MaxBatchCount;
|
|
}
|
|
return batchCount;
|
|
}
|
|
}
|
|
}
|