private static void SplitRingBuffer(UnsafeRingBuffer *q) { //Wrap tail back to 0 for (int i = 0; i < 5; i++) { UnsafeRingBuffer.Push(q, 111); } //First half for (int i = 0; i < 5; i++) { UnsafeRingBuffer.Push(q, i); } //Move head by 5 for (int i = 0; i < 5; i++) { UnsafeRingBuffer.Pop <int>(q, out _); } //Second half (head and tail are now both 5) for (int i = 5; i < 10; i++) { UnsafeRingBuffer.Push(q, i); } //Circular buffer now "ends" in the middle of the underlying array }
public void DequeueTest() { var q = UnsafeRingBuffer.Allocate <int>(10); for (int i = 0; i < 10; i++) { UnsafeRingBuffer.Push(q, i * i); } for (int i = 0; i < 10; i++) { UnsafeRingBuffer.Pop <int>(q, out int num); Assert.AreEqual(i * i, num); } UnsafeRingBuffer.Free(q); }
public bool Pop(out T value) { return(UnsafeRingBuffer.Pop(m_inner, out value)); }