本文整理汇总了C#中CircularBuffer.Put方法的典型用法代码示例。如果您正苦于以下问题:C# CircularBuffer.Put方法的具体用法?C# CircularBuffer.Put怎么用?C# CircularBuffer.Put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CircularBuffer
的用法示例。
在下文中一共展示了CircularBuffer.Put方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OverflowException
public void OverflowException()
{
var buffer = new CircularBuffer<int>(4);
for (int i = 0; i < 32; i++)
buffer.Put(i);
}
示例2: Get
public QueueClient Get(Address address)
{
var key = address.ToString();
var buffer = queueClients.GetOrAdd(key, s =>
{
var b = new CircularBuffer<QueueClientEntry>(numberOfQueueClientsPerAddress);
for (var i = 0; i < numberOfQueueClientsPerAddress; i++)
{
var factory = messagingFactories.Get(address);
b.Put(new QueueClientEntry
{
Client = queueClientCreator.Create(address.Queue, factory)
});
}
return b;
});
var entry = buffer.Get();
if (entry.Client.IsClosed)
{
lock (entry.mutex)
{
if (entry.Client.IsClosed)
{
var factory = messagingFactories.Get(address);
entry.Client = queueClientCreator.Create(address.Queue, factory);
}
}
}
return entry.Client;
}
示例3: Get
public MessagingFactory Get(Address address)
{
var key = address.ToString();
var buffer = MessagingFactories.GetOrAdd(key, s => {
var b = new CircularBuffer<FactoryEntry>(numberOfFactoriesPerAddress);
for(var i = 0; i < numberOfFactoriesPerAddress; i++)
b.Put(new FactoryEntry { Factory = createMessagingFactories.Create(address) });
return b;
});
var entry = buffer.Get();
if (entry.Factory.IsClosed)
{
lock (entry.mutex)
{
if (entry.Factory.IsClosed)
{
entry.Factory = createMessagingFactories.Create(address);
}
}
}
return entry.Factory;
}
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:26,代码来源:ManageMessagingFactoriesLifeCycle.cs
示例4: TestSimple
public void TestSimple()
{
var buffer = new CircularBuffer<int>(16);
var data = new int[8];
buffer.Put(data, 0, 8);
Assert.AreEqual(
8,
buffer.Size);
}
示例5: 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);
}
}
示例6: Should_be_thread_safe
public void Should_be_thread_safe()
{
var maxDegreeOfParallelism = 5;
var numberOfEntries = 2;
var numberOfItems = 100000;
var buffer = new CircularBuffer<BufferEntry>(numberOfEntries, true); // overflow must be allowed
Parallel.For(0, numberOfItems, new ParallelOptions() { MaxDegreeOfParallelism = maxDegreeOfParallelism }, item =>
{
buffer.Put(new BufferEntry());
});
}
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:14,代码来源:When_putting_items_into_circular_buffer.cs
示例7: Put
[TestCase(1, 2, 3, 4, 5)] // One more than of capasity
public void Put(params int[] numbers)
{
// Arrange
const int capasity = 2;
var sut = new CircularBuffer<int>(capasity);
// Act
foreach (var number in numbers)
{
sut.Put(number);
}
// Assert
var shouldContain = numbers.Reverse().Take(capasity).ToList();
sut.Should().Contain(shouldContain);
}
示例8: BasicDOSProtector
public BasicDOSProtector(BasicDosProtectorOptions options)
{
_generalRequestTimes = new CircularBuffer<int>(options.MaxRequestsInTimeframe + 1, true);
_generalRequestTimes.Put(0);
_options = options;
_deeperInspection = new Dictionary<string, CircularBuffer<int>>();
_tempBlocked = new Dictionary<string, int>();
_sessions = new Dictionary<string, int>();
_forgetTimer = new System.Timers.Timer();
_forgetTimer.Elapsed += delegate
{
_forgetTimer.Enabled = false;
List<string> removes = new List<string>();
_blockLockSlim.EnterReadLock();
foreach (string str in _tempBlocked.Keys)
{
if (
Util.EnvironmentTickCountSubtract(Util.EnvironmentTickCount(),
_tempBlocked[str]) > 0)
removes.Add(str);
}
_blockLockSlim.ExitReadLock();
lock (_deeperInspection)
{
_blockLockSlim.EnterWriteLock();
for (int i = 0; i < removes.Count; i++)
{
_tempBlocked.Remove(removes[i]);
_deeperInspection.Remove(removes[i]);
_sessions.Remove(removes[i]);
}
_blockLockSlim.ExitWriteLock();
}
foreach (string str in removes)
{
m_log.InfoFormat("[{0}] client: {1} is no longer blocked.",
_options.ReportingName, str);
}
_blockLockSlim.EnterReadLock();
if (_tempBlocked.Count > 0)
_forgetTimer.Enabled = true;
_blockLockSlim.ExitReadLock();
};
_forgetTimer.Interval = _options.ForgetTimeSpan.TotalMilliseconds;
}
示例9: 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
示例10: Peek
public void Peek()
{
var buffer = new CircularBuffer<int>(16);
for(var i=0;i<8;i++)
buffer.Put(i);
var peek1 = new int[8];
var peek2 = new int[8];
buffer.Peek(peek1, 0, 8);
buffer.Peek(peek2, 0, 8);
for(var i = 0; i < 8; i++)
{
Assert.AreEqual(
peek1[i],
peek2[i]);
}
}
示例11: sourceStream_DataAvailable
private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
{
label10.Text = e.BytesRecorded.ToString();
label11.Text = e.Buffer.Length.ToString();
var buffer = e.Buffer;
var buffer1 = new CircularBuffer<byte>(e.Buffer.Length-100,true);
buffer1.Put(buffer);
//buffer1.Clear();
//MemoryStream memory = new MemoryStream(buffer);
int i = 0;
for (int index = 0; index < e.BytesRecorded; index += 2)
{
short sample = (short)((buffer[index + 1] << 8) | buffer[index]);
// short sample = (short)(buffer[index]);
//short sample=(short)(queue1.Enqueue((byte)index));
float sample32 = sample / 32768f;
t[i] = sample32;
//memory.Dispose();
// short truncated = (short)(Math.Pow(2,15)-1);
// buffer[index]=(byte)(truncated & 0x00ff);
//buffer[index+1]=(byte)((truncated & 0xff00)<<8);
++i;
}
}