本文整理汇总了C#中BufferPool类的典型用法代码示例。如果您正苦于以下问题:C# BufferPool类的具体用法?C# BufferPool怎么用?C# BufferPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BufferPool类属于命名空间,在下文中一共展示了BufferPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: a_write_will_automatically_grow_the_buffer_pool
public void a_write_will_automatically_grow_the_buffer_pool()
{
BufferPool pool = new BufferPool(1, BufferManager);
int initialCapacity = pool.Capacity;
pool[initialCapacity + 14] = 5;
Assert.AreEqual(initialCapacity * 2, pool.Capacity);
}
示例2: length_is_updated_when_index_higher_than_count_set
public void length_is_updated_when_index_higher_than_count_set()
{
BufferPool pool = new BufferPool(1, BufferManager);
Assert.AreEqual(0, pool.Length);
pool[3] = 5;
Assert.AreEqual(4, pool.Length);
}
示例3: SocketServer
static SocketServer()
{
var max = CurrencyStoreSection.Instance.Server.Buffer.MaxLength;
var size = CurrencyStoreSection.Instance.Server.Buffer.Size;
socketArgsPool = new SocketArgsPool(max);
bufferManager = new BufferPool(max * size, size);
allowAllowAnonymous = CurrencyStoreSection.Instance.Authorization.AllowAnonymous;
}
示例4: ReleaseBufferTest
public void ReleaseBufferTest()
{
string strBufferName = string.Empty; // TODO: 初始化为适当的值
long iInitialCapacity = 0; // TODO: 初始化为适当的值
long iBufferSize = 0; // TODO: 初始化为适当的值
BufferPool target = new BufferPool( strBufferName, iInitialCapacity, iBufferSize ); // TODO: 初始化为适当的值
byte[] byteBuffer = null; // TODO: 初始化为适当的值
target.ReleaseBuffer( byteBuffer );
Assert.Inconclusive( "无法验证不返回值的方法。" );
}
示例5: StartSound
public void StartSound()
{
BufferSizeSamples = Sound.MillisecondsToSamples(Global.Config.SoundBufferSizeMs);
MaxSamplesDeficit = BufferSizeSamples;
_sourceID = AL.GenSource();
_bufferPool = new BufferPool();
_currentSamplesQueued = 0;
}
示例6: BufferPool
public void BufferPool()
{
BufferPool bp = new BufferPool(10000);
int ct = 1000;
for (int i = 0; i < ct; i++) {
byte[] b = bp.GetBuffer();
Assert.AreEqual(10000, b.Length);
bp.ReturnBuffer(b);
}
Console.WriteLine("{0} allocations for {1} uses of buffer pool.", bp.NumAllocations, ct);
}
示例7: NetSocket
internal NetSocket(INetAddress address, BufferPool bufferPool, SocketEventArgPool socketPool, Socket baseSocket)
{
this.BufferPool = bufferPool;
this.SocketPool = socketPool;
this.BaseSocket = baseSocket;
this.BaseSocket.NoDelay = true;
this.IsClient = true;
this.OnAccepted = delegate { };
this.OnReceived = delegate { };
this.OnSent = delegate { };
this.OnFault = delegate { };
}
示例8: ThreeThousandGetBuffers
public void ThreeThousandGetBuffers()
{
BufferPool pool = new BufferPool(10 * 1024 * 1024, 1, 1);
//PLAN:
//Just like HundredGetBuffers but with 3000 threads
List<IBuffer> bufferList = new List<IBuffer>();
int threadNumber = 3000;
int sizeOdd = 524288;
int sizeEven = 524288;
AquireBuffersConcurrently(pool, bufferList, threadNumber, sizeOdd, sizeEven);
AssertIsContiguous(bufferList);
Assert.IsTrue(pool.SlabCount == 150 || pool.SlabCount == 151, "SlabCount is " + pool.SlabCount + ". Was expecting 150 or 151");
}
示例9: AquireBuffersConcurrently
private static void AquireBuffersConcurrently(BufferPool pool, List<IBuffer> bufferList, int threadNumber, int sizeOdd, int sizeEven)
{
object bufferList_sync = new object();
ManualResetEvent mre = new ManualResetEvent(false);
for (int i = 0; i < threadNumber; i++)
{
Thread thread = new Thread(delegate(object number)
{
var size = ((int)number % 2 == 1 ? sizeOdd : sizeEven);
//wait for signal
mre.WaitOne();
//Aquire buffer
IBuffer buff = pool.GetBuffer(size);
//Add to Queue
lock (bufferList_sync)
{
bufferList.Add(buff);
}
});
thread.IsBackground = true;
thread.Start(i);
}
Thread.Sleep(500); //ensure all threads are waiting for signal
mre.Set(); //signal event
//Wait till all threads are done
while (true)
{
lock (bufferList)
{
if (bufferList.Count == threadNumber) break;
Thread.Sleep(500);
}
}
}
示例10: StartSound
public void StartSound()
{
BufferSizeSamples = Sound.MillisecondsToSamples(Global.Config.SoundBufferSizeMs);
MaxSamplesDeficit = BufferSizeSamples;
var format = new WaveFormat
{
SamplesPerSecond = Sound.SampleRate,
BitsPerSample = Sound.BytesPerSample * 8,
Channels = Sound.ChannelCount,
FormatTag = WaveFormatTag.Pcm,
BlockAlignment = Sound.BlockAlign,
AverageBytesPerSecond = Sound.SampleRate * Sound.BlockAlign
};
_sourceVoice = new SourceVoice(_device, format);
_bufferPool = new BufferPool();
_runningSamplesQueued = 0;
_sourceVoice.Start();
}
示例11: HundredGetBuffers
public void HundredGetBuffers()
{
BufferPool pool = new BufferPool(10 * 1024 * 1024, 1, 1);
//PLAN:
//Create 100 threads. Odd numbered threads will request buffer sizes of 314567 bytes
//whereas even numbered threads will request buffer sizes of 314574 bytes
//for a total allocation of 31457100 bytes.
//If everything goes well there will be no overlap in allocated buffers
//and there'll be no free space greater than 314574 (the lower number) on total slabs - 1
//and slabs should be 4
List<IBuffer> bufferList = new List<IBuffer>();
int threadNumber = 100;
int sizeOdd = 314567;
int sizeEven = 314574;
AquireBuffersConcurrently(pool, bufferList, threadNumber, sizeOdd, sizeEven);
AssertIsContiguous(bufferList);
Assert.IsTrue(pool.SlabCount == 3 || pool.SlabCount == 4, "SlabCount is " + pool.SlabCount + ". Was expecting 3 or 4");
}
示例12: length_is_set_when_setting_length
public void length_is_set_when_setting_length()
{
BufferPool pool = new BufferPool(1, BufferManager);
pool.SetLength(5000, false);
Assert.AreEqual(5000, pool.Length);
}
示例13: the_byte_array_should_be_the_same_length_as_the_pool_with_data
public void the_byte_array_should_be_the_same_length_as_the_pool_with_data()
{
BufferPool pool = new BufferPool(5, BufferManager);
for (int i = 0; i < 500; i++)
{
pool[i] = 12;
}
Assert.AreEqual(500, pool.ToByteArray().Length);
}
示例14: data_is_written_to_the_internal_buffer
public void data_is_written_to_the_internal_buffer()
{
BufferPool pool = new BufferPool(1, BufferManager);
byte[] data = { 1, 2, 3, 4, 5 };
pool.Append(data);
for (byte i = 0; i < 5; i++)
{
Assert.AreEqual(i + 1, pool[i]);
}
}
示例15: a_write_past_end_will_check_out_a_buffer_from_the_buffer_pool
public void a_write_past_end_will_check_out_a_buffer_from_the_buffer_pool()
{
BufferPool pool = new BufferPool(1, BufferManager);
int initial = BufferManager.AvailableBuffers;
pool[pool.Capacity + 14] = 5;
Assert.AreEqual(initial - 1, BufferManager.AvailableBuffers);
}