Alex Rivera | Logout

How do I implement a circular list (ring buffer) in C?

Asked 2008-10-18T20:59:26.313
32

How do I implement a circular list that overwrites the oldest entry when it's full?

For a little background, I want to use a circular list within GWT; so using a 3rd party lib is not what I want.

Edit
Report

1 Answer

1

Use an array and keep a variable P with the first available position.

Increase P every time you add a new element.

To know the equivalent index of P in your array do (P % n) where n is the size of your array.

answered 2008-10-18T21:12:48.923

Your Answer