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


C# RingBuffer类代码示例

本文整理汇总了C#中RingBuffer的典型用法代码示例。如果您正苦于以下问题:C# RingBuffer类的具体用法?C# RingBuffer怎么用?C# RingBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ArchivingEngine

 public ArchivingEngine(
     string sourceRootFolder,
     string targetRootFolder,
     ArchivingSettings settings,
     TotalStatistics statistics,
     ILog log)
 {
     this.sourceRootFolder = sourceRootFolder;
     this.targetRootFolder = targetRootFolder;
     this.statistics = statistics;
     this.settings = settings;
     this.log = log;
     queue = new RingBuffer<Processing>();
     processingDistributor = new ProcessingDistributor(
         sourceRootFolder,
         targetRootFolder,
         statistics,
         queue,
         log);
     processingPool = new PipelinesPool(processingDistributor);
     retrievingDistributor = new RetrievingDistributor(
         queue,
         log);
     retrievingPool = new PipelinesPool(retrievingDistributor);
 }
开发者ID:vbogretsov,项目名称:threading,代码行数:25,代码来源:ArchivingEngine.cs

示例2: setUp

 public void setUp()
 {
     ringBuffer = new RingBuffer<StubEntry>(new StubFactory(), 20, new SingleThreadedStrategy(),
                                            new BusySpinStrategy<StubEntry>());
     consumerBarrier = ringBuffer.CreateConsumerBarrier();
     producerBarrier = ringBuffer.CreateProducerBarrier(new NoOpConsumer(ringBuffer));
 }
开发者ID:TimGebhardt,项目名称:Disruptor.NET,代码行数:7,代码来源:RingBufferTests.cs

示例3: PerfTestThreadsWithDequeues

        public void PerfTestThreadsWithDequeues()
        {
            RingBuffer<string> ringBuffer = new RingBuffer<string>(1000);

            Stopwatch ringWatch = new Stopwatch();
            List<Task> ringTasks = new List<Task>();
            for (int t = 0; t < 10; t++)
            {
                ringTasks.Add(new Task(() =>
                {
                    for (int i = 0; i < 1000000; i++)
                    {
                        ringBuffer.Enqueue("StringOfFun");
                    }
                }));

            }
            for (int t = 0; t < 10; t++)
            {
                ringTasks.Add(new Task(() =>
                {
                    for (int i = 0; i < 1000000; i++)
                    {
                        string foo;
                        ringBuffer.TryDequeue(out foo);
                    }
                }));
            }
            ringWatch.Start();
            ringTasks.ForEach(t => t.Start());
            Task.WaitAny(ringTasks.ToArray());
            ringWatch.Stop();

            Assert.That(ringWatch.ElapsedMilliseconds, Is.LessThan(800));
        }
开发者ID:paulsuart,项目名称:rebelcmsxu5,代码行数:35,代码来源:RingBufferFixture.cs

示例4: OneToOneSequencedPollerThroughputTest

 public OneToOneSequencedPollerThroughputTest()
 {
     _ringBuffer = RingBuffer<ValueEvent>.CreateSingleProducer(ValueEvent.EventFactory, _bufferSize, new YieldingWaitStrategy());
     _poller = _ringBuffer.NewPoller();
     _ringBuffer.AddGatingSequences(_poller.Sequence);
     _pollRunnable = new PollRunnable(_poller);
 }
开发者ID:disruptor-net,项目名称:Disruptor-net,代码行数:7,代码来源:OneToOneSequencedPollerThroughputTest.cs

示例5: XInputDeviceManager

		public XInputDeviceManager()
		{
			if (InputManager.XInputUpdateRate == 0)
			{
				timeStep = Mathf.FloorToInt( Time.fixedDeltaTime * 1000.0f );
			}
			else
			{
				timeStep = Mathf.FloorToInt( 1.0f / InputManager.XInputUpdateRate * 1000.0f );
			}

			bufferSize = (int) Math.Max( InputManager.XInputBufferSize, 1 );

			for (int deviceIndex = 0; deviceIndex < maxDevices; deviceIndex++)
			{
				gamePadState[deviceIndex] = new RingBuffer<GamePadState>( bufferSize );
			}

			StartWorker();

			for (int deviceIndex = 0; deviceIndex < maxDevices; deviceIndex++)
			{
				devices.Add( new XInputDevice( deviceIndex, this ) );
			}

			Update( 0, 0.0f );
		}
开发者ID:DarrenTsung,项目名称:simple-clicker,代码行数:27,代码来源:XInputDeviceManager.cs

示例6: Initialize

 public void Initialize(RingBuffer<InboundMessageProcessingEntry> ringBuffer)
 {
     _ringBuffer = ringBuffer;
     _ipEndPoint = _endpoint.EndPoint;
     _receiver.RegisterCallback(_ipEndPoint, DoReceive);
     _receiver.ListenToEndpoint(_ipEndPoint);
 }
开发者ID:jbouzaglou,项目名称:PetPigeonsESB,代码行数:7,代码来源:CustomTcpTransportWireDataReceiver.cs

示例7: ActivateOptions

 public override void ActivateOptions()
 {
     base.ActivateOptions();
     pendingAppends = new RingBuffer<LoggingEvent>(QueueSizeLimit);
     pendingAppends.BufferOverflow += OnBufferOverflow;
     StartAppendTask();
 }
开发者ID:JohnDRoach,项目名称:Log4Net.Async,代码行数:7,代码来源:AsyncAdoAppender.cs

示例8: AddItemsToBufferOfSetSize_RemovesItemsFirstAddedToBufferToFitInMoreItems

    public void AddItemsToBufferOfSetSize_RemovesItemsFirstAddedToBufferToFitInMoreItems()
    {
      var buffer = new RingBuffer<string>(2);
      buffer.Add("1");
      buffer.Add("2");

      List<string> items = buffer.ToList();
      Assert.AreEqual("1", items[0]);
      Assert.AreEqual("2", items[1]);

      buffer.Add("3");
      items = buffer.ToList();
      Assert.AreEqual("2", items[0]);
      Assert.AreEqual("3", items[1]);

      buffer.Add("4");
      items = buffer.ToList();
      Assert.AreEqual("3", items[0]);
      Assert.AreEqual("4", items[1]);

      buffer.Add("5");
      items = buffer.ToList();
      Assert.AreEqual("4", items[0]);
      Assert.AreEqual("5", items[1]);
    }
开发者ID:tiwariritesh7,项目名称:devdefined-tools,代码行数:25,代码来源:RingBufferTests.cs

示例9: StDevXyProduct

    /// <summary>
    /// Returns the product of the stdev of the x and y components of the previous n mouse states,
    /// which makes for a very good input trigger. There are many optimizations available for this function.
    /// 
    /// The stdev strategy parameters must be based upon the physical problem of detecting clicks via a
    /// concentration of points within a region. This means that the Hz rate of the sensor is an input,
    /// as well as other physical characteristics of the device and its current calibration.
    /// 
    /// There need be no weighting in this function either; since we assume the user is focused on a given point, all
    /// points captured within a sample of time window t are estimates of the true 'hidden' value of the current points.
    /// </summary>
    /// <param name="numPoints">The number of previous points to include in the stdev-xy product.</param>
    /// <returns></returns>
    public double StDevXyProduct(int numPoints, RingBuffer<EyeDatum> sensorData)
    {
      int i;
      double mu_x = 0.0, mu_y = 0.0;
      double var_x = 0.0, var_y = 0.0;

      //get the means
      for (i = 0; i < numPoints && i < sensorData.Count; i++)
      {
        mu_x += sensorData[i].MouseData.X;
        mu_y += sensorData[i].MouseData.Y;
      }
      mu_x /= (double)i;
      mu_y /= (double)i;
      
      //get the variance of the x and y coordinates in this set
      for (i = 0; i < numPoints && i < sensorData.Count; i++)
      {
        var_x += ((sensorData[i].MouseData.X - mu_x) * (sensorData[i].MouseData.X - mu_x));
        var_y += ((sensorData[i].MouseData.Y - mu_y) * (sensorData[i].MouseData.Y - mu_y));
      }

      //optimization TODO: there is no need for expensive square-root for the trigger we're looking for;
      //by laws of exponents, (x^0.5)(y^0.5) == (x*y)^0.5, and thus the sqrt is actually unnecessary for
      //a trigger, since the trigger baseline can simply be squared. And also if we're careful wrt overflow.
      return Math.Sqrt(var_x) * Math.Sqrt(var_y);
    }
开发者ID:niceyeti,项目名称:MissileCommand,代码行数:40,代码来源:EyeSensorFilter.cs

示例10: EyeDevice

    public EyeDevice(int sensorHz)
    {
      _exit = false;
      _pendingDatum = false;
      //the data history should exceed the Hz of sensors on the market; this gives 2 seconds history for a 250Hz sensor.
      //A larger value could be used for historical or other vector analysis on the extended inputs.
      SENSOR_DATA_HISTORY = 500;
      _eyeDataBuffer = new RingBuffer<EyeDatum>(SENSOR_DATA_HISTORY);
      _filter = new EyeSensorFilter();
      _newDatumLock = new Object();

      //the number of pending datum misses by the consumer thread
      _misses = 0;

      if (sensorHz >= 500)
      {
        Console.WriteLine("ERROR sensorHz="+sensorHz+" is to high sensitivity for sensor poll. Large (>500Hz) sensorHz values");
        Console.WriteLine("may prevent sensor data from being read. Re-evaluate algorithms in EyeDevice.");
      }

      //_currentState must have some initial value, or readers will get null ref
      _currentState = Mouse.GetState();

      //Set the poll scan time. Note this math is intentionally incorrect: using 1200 instead of 1000 is intended so that the
      //sensor-polling thread always runs slightly faster than the rate at which manufacturers claim for their tracker Hz.
      _sensorScanTime_ms = 1200 / sensorHz;
      _computationScanTime_ms = _sensorScanTime_ms;
      //launch the sensor polling thread.
      _pollingThread = new Thread(new ThreadStart(_pollSensor));
      _pollingThread.Start();

      //kick the computation thread
      _computationThread = new Thread(new ThreadStart(_runComputations));
      _computationThread.Start();
    }
开发者ID:niceyeti,项目名称:MissileCommand,代码行数:35,代码来源:EyeDevice.cs

示例11: ClearTest_notempty

 public void ClearTest_notempty()
 {
     RingBuffer<int> rb = new RingBuffer<int>(4);
     rb.Add(7);
     Assert.IsFalse(rb.IsEmpty);
     rb.Clear();
     Assert.IsTrue(rb.IsEmpty);
 }
开发者ID:BobPusateri,项目名称:RingBuffer,代码行数:8,代码来源:RingBuffer_Test.cs

示例12: Initialize

 public void Initialize(RingBuffer<InboundMessageProcessingEntry> ringBuffer)
 {
     _ringBuffer = ringBuffer;
     foreach (IWireReceiverTransport wireReceiverTransport in _transports)
     {
         wireReceiverTransport.Initialize(ringBuffer);
     }
 }
开发者ID:jbouzaglou,项目名称:PetPigeonsESB,代码行数:8,代码来源:IDataReceiver.cs

示例13: RetrievedInCorrectOrder

 public void RetrievedInCorrectOrder() {
     RingBuffer<int> _buffer = new RingBuffer<int>(iterations);
     populateBuffer(iterations, _buffer);
     for(int i = 0; i < iterations; i++) {
         int _tmp = _buffer.Get();
         Assert.AreEqual(i, _tmp, "Incorrect Sequence");
     }
 }
开发者ID:Joe821,项目名称:RingBuffer.NET,代码行数:8,代码来源:RingBufferTests.cs

示例14: SetUp

        public void SetUp()
        {
            _sequencerMock = new Mock<ISequencer>();
            _sequencer = _sequencerMock.Object;

            _sequencerMock.SetupGet(x => x.BufferSize).Returns(16);
            _ringBuffer = new RingBuffer<StubEvent>(StubEvent.EventFactory, _sequencer);
        }
开发者ID:disruptor-net,项目名称:Disruptor-net,代码行数:8,代码来源:RingBufferWithMocksTest.cs

示例15: ValuePublisher

 public ValuePublisher(Barrier cyclicBarrier
 , RingBuffer<ValueEvent> ringBuffer
 , long iterations)
 {
     this.cyclicBarrier = cyclicBarrier;
     this.ringBuffer = ringBuffer;
     this.iterations = iterations;
 }
开发者ID:bingyang001,项目名称:disruptor-net-3.3.0-alpha,代码行数:8,代码来源:ValuePublisher.cs


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