News for hackers. Stuff that matters.
Re:Show HN: Revring, a circular buffer with zero memory waste by jhallenworld on Thursday June 18, 2015 @08:50PM (#9742483)
A conceptually simpler way to do this is to assign one (or more) extra bits in the head an tail pointers. For example, for a 512 entry ring, use 16-bit indices. Whenever you index the ring, and the index with 511 before performing the index.

  Write to ring: ring[511&(head++)] = data

  Read from ring: data = ring[511&(tail++)]

  Ring is empty: head == tail

  Ring is full: tail + 512 == head

There are no comments on this comment yet.