Project Description
This is a C# implementation of the classic data structure for a circular buffer, otherwise also known as a ring buffer.
The ring buffer is derived from MemoryStream for managing its underlying memory buffer.
A twist to this ring buffer implementation is that it allows the buffer to be grown dynamically, but this behavior can also be turned off by setting the CanGrow property to false.
The buffer is grown based on the dynamics of the Stream class:
Writing to the stream moves the tail position and reading from the stream moves the head position.
If the tail position wraps around to the head position the buffer will be grown with the next Write.
In a traditional implementation attempting to write past the head would incur either an exception or blocking behavior.
The writing and reading can be thought of as producing and consuming. If the consuming of bytes in the ring buffer is slower than the producing and the producing is non-stop then allowing automatic growing is probably not a good idea.