A generic ring-buffer implementation.