title: scala collections circular buffer
body: <p>Just messing about here, with circular buffers. Is this a sensible implementation or is there a faster/more reliable way to skin this cat?</p>
  
  <pre><code>class CircularBuffer[T](size: Int)(implicit mf: Manifest[T]) {
  
      private val arr = new scala.collection.mutable.ArrayBuffer[T]()
  
      private var cursor = 0
  
      val monitor = new ReentrantReadWriteLock()
  
      def push(value: T) {
        monitor.writeLock().lock()
        try {
          arr(cursor) = value
          cursor += 1
          cursor %= size
        } finally {
          monitor.writeLock().unlock()
        }
      }
  
      def getAll: Array[T] = {
        monitor.readLock().lock()
        try {
          val copy = new Array[T](size)
          arr.copyToArray(copy)
          copy
        } finally {
          monitor.readLock().unlock()
        }
      }
    }
  </code></pre>