Created
December 17, 2015 13:40
-
-
Save jameshulse/20862c47544b77884dff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CircularBuffer<T> | |
{ | |
private readonly int _size; | |
private readonly T[] _items; | |
private int _writeLocation = -1; | |
private readonly object _lock = new object(); | |
public CircularBuffer(int size) | |
{ | |
_size = size; | |
_items = new T[size]; | |
} | |
public void Add(T item) | |
{ | |
lock (_lock) | |
{ | |
_writeLocation++; | |
_writeLocation %= _size; | |
_items[_writeLocation] = item; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment