本文整理汇总了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);
}
示例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);
}
}
示例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