ZeroEffect Posted March 23, 2008 Posted March 23, 2008 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. 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 Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
Administrators PlausiblyDamp Posted March 23, 2008 Administrators Posted March 23, 2008 (edited) 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. Edited March 23, 2008 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ZeroEffect Posted March 29, 2008 Author Posted March 29, 2008 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 Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
ZeroEffect Posted April 11, 2008 Author Posted April 11, 2008 I should have looked a little more, I found this and it works great! System.Collections.Queue Thanks for the help ZeroEffect Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.