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


C# CircularBuffer.Get方法代码示例

本文整理汇总了C#中CircularBuffer.Get方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.Get方法的具体用法?C# CircularBuffer.Get怎么用?C# CircularBuffer.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CircularBuffer的用法示例。


在下文中一共展示了CircularBuffer.Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Serialize

        public byte[] Serialize(CircularBuffer<Packet> buffer)
        {
            if (buffer.Size == 0)
                return null;

            var json = JsonConvert.SerializeObject(buffer.Get());
            return Encoding.UTF8.GetBytes(json);
        }
开发者ID:pjc0247,项目名称:Merona.JsonProtocol.cs,代码行数:8,代码来源:JsonMarshaler.cs

示例2: CircularBufferGetPutSkipTest

        public void CircularBufferGetPutSkipTest()
        {
            {
                CircularBuffer<int> buffer = new CircularBuffer<int>(3, true);
                buffer.Put(1);
                buffer.Put(2);
                buffer.Put(3);
                buffer.Put(4);

                int get1 = buffer.Get();
                int get2 = buffer.Get();

                Assert.AreEqual(get1, 2);
                Assert.AreEqual(get2, 3);
            }
            {
                CircularBuffer<int> buffer = new CircularBuffer<int>(3, true);
                buffer.Put(1);
                buffer.Put(2);
                buffer.Put(3);
                buffer.Put(4);
                buffer.Put(5);

                int get1 = buffer.Peek(); // 3
                int get2 = buffer.Peek(0); // 3
                int get3 = buffer.Peek(1); // 4
                int get4 = buffer.Peek(2); // 5

                Assert.AreEqual(get1, 3);
                Assert.AreEqual(get2, 3);
                Assert.AreEqual(get3, 4);
                Assert.AreEqual(get4, 5);

                List<int> getRange = buffer.PeekRange(0);
                Assert.AreEqual(getRange.Count, 3);
                Assert.AreEqual(getRange[0], 3);
                Assert.AreEqual(getRange[1], 4);
                Assert.AreEqual(getRange[2], 5);
            }
        }
开发者ID:HongSeokHwan,项目名称:legacy,代码行数:40,代码来源:CircularBufferTest.cs

示例3: Should_be_thread_safe

        public void Should_be_thread_safe()
        {
            var maxDegreeOfParallelism = 5;
            var numberOfEntries = 2;

            var buffer = new CircularBuffer<BufferEntry>(numberOfEntries);

            Parallel.For(0, numberOfEntries, new ParallelOptions() { MaxDegreeOfParallelism = maxDegreeOfParallelism }, item =>
            {
                buffer.Put(new BufferEntry());
            });

            Parallel.For(0, 100000, new ParallelOptions() { MaxDegreeOfParallelism = maxDegreeOfParallelism }, item =>
            {
                buffer.Get();
            });

        }
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:18,代码来源:When_getting_items_from_circular_buffer.cs


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