本文整理汇总了C#中CircularBuffer.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.Reset方法的具体用法?C# CircularBuffer.Reset怎么用?C# CircularBuffer.Reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CircularBuffer
的用法示例。
在下文中一共展示了CircularBuffer.Reset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Recycle
public void Recycle(CircularBuffer<IFrame> buffer)
{
buffer.Reset();
frameBufferPool.PutBack(buffer);
}
示例2: CircularBuffer_ProduceConsume
public void CircularBuffer_ProduceConsume()
{
CircularBuffer<byte> cb = new CircularBuffer<byte>(50);
Assert.AreEqual(50, cb.Capacity);
// Initial state
Assert.AreEqual(0, cb.Start);
Assert.AreEqual(0, cb.Length);
Assert.AreEqual(0, cb.ReadLength);
Assert.AreEqual(0, cb.End);
Assert.AreEqual(50, cb.Free);
Assert.AreEqual(50, cb.WriteLength);
// Test 1: Allocate 50 bytes
cb.Produce(50);
Assert.AreEqual(0, cb.Start);
Assert.AreEqual(50, cb.Length);
Assert.AreEqual(50, cb.ReadLength);
Assert.AreEqual(0, cb.End);
Assert.AreEqual(0, cb.Free);
Assert.AreEqual(0, cb.WriteLength);
// Test 2: Free 50 bytes
cb.Consume(50);
Assert.AreEqual(0, cb.Start);
Assert.AreEqual(0, cb.Length);
Assert.AreEqual(0, cb.ReadLength);
Assert.AreEqual(0, cb.End);
Assert.AreEqual(50, cb.Free);
Assert.AreEqual(50, cb.WriteLength);
// Test 3: Allocate 25 bytes
cb.Produce(25);
Assert.AreEqual(0, cb.Start);
Assert.AreEqual(25, cb.Length);
Assert.AreEqual(25, cb.ReadLength);
Assert.AreEqual(25, cb.End);
Assert.AreEqual(25, cb.Free);
Assert.AreEqual(25, cb.WriteLength);
// Test 4: Free 24 bytes
cb.Consume(24);
Assert.AreEqual(24, cb.Start);
Assert.AreEqual(1, cb.Length);
Assert.AreEqual(1, cb.ReadLength);
Assert.AreEqual(25, cb.End);
Assert.AreEqual(49, cb.Free);
Assert.AreEqual(25, cb.WriteLength);
// Test 5: Alocate 49 bytes
cb.Produce(49);
Assert.AreEqual(24, cb.Start);
Assert.AreEqual(50, cb.Length);
Assert.AreEqual(26, cb.ReadLength);
Assert.AreEqual(24, cb.End);
Assert.AreEqual(0, cb.Free);
Assert.AreEqual(0, cb.WriteLength);
// Test 6: Reset
cb.Reset();
Assert.AreEqual(0, cb.Start);
Assert.AreEqual(0, cb.Length);
Assert.AreEqual(0, cb.ReadLength);
Assert.AreEqual(0, cb.End);
Assert.AreEqual(50, cb.Free);
Assert.AreEqual(50, cb.WriteLength);
// Test 7: Test full wrapping around
cb.Produce(25);
cb.Consume(25);
cb.Produce(50);
Assert.AreEqual(25, cb.Start);
Assert.AreEqual(50, cb.Length);
Assert.AreEqual(25, cb.ReadLength);
Assert.AreEqual(25, cb.End);
Assert.AreEqual(0, cb.Free);
Assert.AreEqual(0, cb.WriteLength);
// Test 8: Free all data
cb.Consume(50);
Assert.AreEqual(25, cb.Start);
Assert.AreEqual(0, cb.Length);
Assert.AreEqual(0, cb.ReadLength);
Assert.AreEqual(25, cb.End);
Assert.AreEqual(50, cb.Free);
Assert.AreEqual(25, cb.WriteLength);
}
示例3: CircularBufferExt_EncoderConvert_Overfill
public void CircularBufferExt_EncoderConvert_Overfill()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Encoder e = enc.GetEncoder();
char[] c = new char[] { 'A', 'B', '€', 'C' };
CircularBuffer<byte> cb = new CircularBuffer<byte>(20);
int bu;
int cu;
bool complete;
for (int i = 15; i < 20; i++) {
System.Diagnostics.Trace.WriteLine("With " + (20 - i).ToString() + " bytes free");
e.Reset();
cb.Reset();
cb.Produce(i);
e.Convert(c, 0, 4, cb, false, out cu, out bu, out complete);
System.Diagnostics.Trace.WriteLine(" cu=" + cu.ToString() + "; bu=" + bu.ToString());
Assert.IsFalse(complete);
Assert.IsTrue(bu <= 20 - i);
}
}
示例4: CircularBuffer_AppendBuffer
public void CircularBuffer_AppendBuffer()
{
CircularBuffer<char> cb1 = new CircularBuffer<char>(20);
CircularBuffer<char> cb2 = new CircularBuffer<char>(20);
// Read is one chunk, write is one chunk
cb2.Produce(3);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(3);
cb1.Append(cb2);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is one chunk, but read is two chunks
cb1.Reset();
cb2.Reset();
cb2.Produce(15);
cb2.Consume(14);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(1);
cb1.Append(cb2);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is two chunks, read is one chunk
cb1.Reset();
cb2.Reset();
cb1.Produce(10);
cb1.Consume(9);
cb2.Append("123456789012345".ToCharArray());
cb1.Append(cb2);
cb1.Consume(1);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is two chunks, read is two chunks, readlength < writelength
cb1.Reset();
cb2.Reset();
cb1.Produce(10);
cb1.Consume(9);
cb2.Produce(15);
cb2.Consume(14);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(1);
cb1.Append(cb2);
cb1.Consume(1);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
// Write is two chunks, read is two chunks, readlength > writelength
cb1.Reset();
cb2.Reset();
cb1.Produce(10);
cb1.Consume(9);
cb2.Produce(7);
cb2.Consume(6);
cb2.Append("123456789012345".ToCharArray());
cb2.Consume(1);
cb1.Append(cb2);
cb1.Consume(1);
Assert.AreEqual(15, cb1.Length);
Assert.AreEqual(5, cb1.Free);
Assert.AreEqual("123456789012345", cb1.GetString());
}
示例5: CircularBufferExt_EncoderConvert
public void CircularBufferExt_EncoderConvert()
{
Encoding enc = Encoding.GetEncoding("UTF-8");
Encoder e = enc.GetEncoder();
char[] c = new char[] { 'A', 'B', '€', 'C' };
CircularBuffer<byte> cb = new CircularBuffer<byte>(20);
int bu;
int cu;
bool complete;
e.Convert(c, 0, 3, cb, false, out cu, out bu, out complete);
Assert.AreEqual(3, cu);
Assert.AreEqual(5, bu);
Assert.AreEqual(5, cb.Length);
Assert.IsTrue(complete);
e.Reset();
cb.Reset();
cb.Produce(17);
cb.Consume(17);
e.Convert(c, 0, 4, cb, false, out cu, out bu, out complete);
Assert.AreEqual(4, cu);
Assert.AreEqual(6, bu);
Assert.AreEqual(6, cb.Length);
Assert.IsTrue(complete);
}