Example #1
0
 public RingBufferReadBenchmarks()
 {
     _ringBuffer                = new RingBuffer <Event>(() => new Event(), new SingleProducerSequencer(4096, new BusySpinWaitStrategy()));
     _valueRingBuffer           = new ValueRingBuffer <ValueEvent>(() => new ValueEvent(), new SingleProducerSequencer(4096, new BusySpinWaitStrategy()));
     _unmanagedRingBufferMemory = UnmanagedRingBufferMemory.Allocate(4096, () => new ValueEvent());
     _unmanagedRingBuffer       = new UnmanagedRingBuffer <ValueEvent>(_unmanagedRingBufferMemory, ProducerType.Single, new BusySpinWaitStrategy());
 }
 public void ShouldNotCreateRingBufferWithInvalidEventSize(int eventSize)
 {
     using (var memory = UnmanagedRingBufferMemory.Allocate(1, 1))
     {
         Assert.Throws <ArgumentException>(() => GC.KeepAlive(new UnmanagedRingBuffer <StubUnmanagedEvent>(memory.PointerToFirstEvent, eventSize, new SingleProducerSequencer(1))));
     }
 }
    private static IValueRingBuffer <StubUnmanagedEvent> CreateRingBuffer(int size, ProducerType producerType, List <UnmanagedRingBufferMemory> memoryList)
    {
        var memory = UnmanagedRingBufferMemory.Allocate(size, () => new StubUnmanagedEvent(-1));

        memoryList.Add(memory);

        return(new UnmanagedRingBuffer <StubUnmanagedEvent>(memory, producerType, new BlockingWaitStrategy()));
    }
    public void ShouldGetEventFromSequence(long sequence)
    {
        var index = 0;

        using var memory = UnmanagedRingBufferMemory.Allocate(32, () => new StubUnmanagedEvent(index++));
        var ringBuffer = new UnmanagedRingBuffer <StubUnmanagedEvent>(memory, ProducerType.Single, new BlockingWaitStrategy());

        ref var evt = ref ringBuffer[sequence];
Example #5
0
        protected override IValueRingBuffer <StubUnmanagedEvent> CreateRingBuffer(int size, ProducerType producerType)
        {
            var memory = UnmanagedRingBufferMemory.Allocate(size, () => new StubUnmanagedEvent(-1));

            _memoryList.Add(memory);

            return(new UnmanagedRingBuffer <StubUnmanagedEvent>(memory, producerType, new BlockingWaitStrategy()));
        }
    private UnmanagedRingBuffer <T> CreateSingleProducer <T>(Func <T> eventFactory, int size)
        where T : unmanaged
    {
        var memory = UnmanagedRingBufferMemory.Allocate(size, eventFactory);

        _memoryList.Add(memory);

        return(new UnmanagedRingBuffer <T>(memory, ProducerType.Single, new BlockingWaitStrategy()));
    }
Example #7
0
        public OneToOneSequencedBatchUnmanagedThroughputTest()
        {
            _memory     = UnmanagedRingBufferMemory.Allocate(_bufferSize, PerfValueEvent.Size);
            _ringBuffer = new UnmanagedRingBuffer <PerfValueEvent>(_memory, ProducerType.Single, new YieldingWaitStrategy());
            var sequenceBarrier = _ringBuffer.NewBarrier();

            _handler             = new AdditionEventHandler();
            _batchEventProcessor = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, _handler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
Example #8
0
        public void ShouldReadValueFromPointer()
        {
            var index = 0;

            using (var memory = UnmanagedRingBufferMemory.Allocate(2048, () => new StubUnmanagedEvent(index++)))
            {
                for (var i = 0; i < memory.EventCount; i++)
                {
                    var evt = Util.ReadValue <StubUnmanagedEvent>(memory.PointerToFirstEvent, i, memory.EventSize);

                    Assert.AreEqual(new StubUnmanagedEvent(i), evt);
                }
            }
        }
Example #9
0
        public void ShouldConvertMemoryToArray()
        {
            var index = 0;

            using (var memory = UnmanagedRingBufferMemory.Allocate(32, () => new Data {
                Value1 = index++
            }))
            {
                var array = memory.ToArray <Data>();

                var expectedArray = Enumerable.Range(0, 32).Select(i => new Data {
                    Value1 = i
                }).ToArray();
                Assert.AreEqual(expectedArray, array);
            }
        }
Example #10
0
        public unsafe void ShouldCreateMemoryFromSize()
        {
            using (var memory = UnmanagedRingBufferMemory.Allocate(1024, 8))
            {
                Assert.AreEqual(1024, memory.EventCount);
                Assert.AreEqual(8, memory.EventSize);

                var pointer = (Data *)memory.PointerToFirstEvent;

                for (var i = 0; i < memory.EventCount; i++)
                {
                    var data = pointer[i];
                    Assert.AreEqual(0, data.Value1);
                    Assert.AreEqual(0, data.Value2);
                }
            }
        }
 public void SetUp()
 {
     _executor  = new StubExecutor();
     _memory    = UnmanagedRingBufferMemory.Allocate(4, TestValueEvent.Size);
     _disruptor = new UnmanagedDisruptor <TestValueEvent>(_memory.PointerToFirstEvent, _memory.EventSize, _memory.EventCount, _executor);
 }