当前位置: 首页>>代码示例>>C#>>正文


C# CircularBuffer.Reset方法代码示例

本文整理汇总了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);
 }
开发者ID:ReinhardHsu,项目名称:NetGain,代码行数:5,代码来源:NetContext.cs

示例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);
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:87,代码来源:CircularBufferTest.cs

示例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);
            }
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:22,代码来源:CircularBufferTest.cs

示例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());
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:73,代码来源:CircularBufferTest.cs

示例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);
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:27,代码来源:CircularBufferTest.cs


注:本文中的CircularBuffer.Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。