ver 2 from http://en.wikipedia.org/wiki/Circular_buffer with fill count