Circular Buffer FIFO help

ZeroEffect

Junior Contributor
Joined
Oct 24, 2004
Messages
204
Location
Detroit, MI
I know nothing of data structures so I am lost when it comes to even getting the code started. I do have the concept in mind of what I need to do.

1. Pass data to a buffer.
2. when the buffer becomes full dump the first in data
3. move all other data up
4. add new data to the end.
5. When data is needed from the buffer garb it from the end while it is still being written to the front.

So there is my understanding of the circular buffer concept .

I haven't really found an example I could understand what was being done.

Visual Basic:
Dim delayBuff(9) as string
Dim buffPos as integer = 0
Dim blnHasData as boolean = False

Private Sub CBuffer(strData as string)
Dim I as Integer
Dim J as Integer
Dim K as Integer

For I = 1 to 9
    J = 10 - I
    k = 9 - I
    delayBuff(J) = delayBuff(K)  'Shift the buffer up one and remove the last bit of data
    next
    delayBuff(0) = strData

End Sub

This doesn't seem very efficient to me.

Thanks

ZeroEffect
 
Actually moving the data in memory to remove old items is going to be a major performance hit as the buffer gets large. Ideally you would have a 'pointer' to the current location in the buffer for writing and another for reading. This would remove the need to physically be moving raw bytes around.

http://www.codeproject.com/KB/recipes/circularbuffer.aspx has a sample with source available - the GUI looks pretty good at explaining the concepts as well. The sample is a .Net 1 app and is using object for everything - converting to generics is no more than 10 minutes work though.
 
Last edited:
Thank you PD this is was the type of tutorial/example I was looking for. I have been on vacation and now that I am back I look forward to taking this apart and learning how it works.

Thank You Again,

ZeroEffect
 
Back
Top