Page 1 of 1

Accessing data from within a circular buffer

Posted: Mon Aug 08, 2016 6:34 am
by Zane
Hi,

A feature that i think would be handy would be to set a pointer in the buffer to access data from a given point. Instead of having to do a whole lot of successive reads to get to the data you need, setting the pointer you could access it directly. If you think this is a worthy additional feature, it would be great to see. :D

Re: Accessing data from within a circular buffer

Posted: Mon Aug 08, 2016 9:48 am
by Benj
Hi Zane,

I'm not sure how best to implement something like this. Would you be throwing the skipped data away or would you still need to access it?

Giving direct control to the read pointer means you have to first know where you are in the buffer so you can then skip the required number of bytes which could get a bit messy.

I could do a GetByteFromIdx macro but you would also probably need a GetReadIdx macro and so it starts getting complicated.

Re: Accessing data from within a circular buffer

Posted: Mon Aug 08, 2016 11:31 am
by Zane
Hi benj,
Giving direct control to the read pointer means you have to first know where you are in the buffer so you can then skip the required number of bytes which could get a bit messy.
To use this function i would use the buffer so it was configured to "store x values first", so once the buffer was full no more data would be placed into the buffer. After flushing the buffer and loading data into the buffer, the data will go from byte 0 through to byte N. A "get byte" operation at the moment will get byte 0 and then the next "get byte" operation would get byte 1 and so on. So in this mode setting the pointer to say byte 15 and then doing a "get byte" operation gets the contents of byte 15 without having to a whole lot of reads to access this data.
Would you be throwing the skipped data away or would you still need to access it?
With any skipped data it would be fine to leave that alone. Once the data from the string that has been placed into the buffer has been processed a "flush buffer" operation would be used to clear the buffer out and set the pointer back to zero ready for the next string of data to be placed into the buffer.
I could do a GetByteFromIdx macro but you would also probably need a GetReadIdx macro and so it starts getting complicated.
I can see what you mean with things getting messy, if the buffer was configured as a "store last x values" so it kept overwriting itself you would always need to know where the pointer was. It would be my intention to use this function only when you were in the "store x values first" mode. Could it be made so this function was only available when the buffer was configured in this mode? Does this sound like it is a workable idea?

Thanks

Re: Accessing data from within a circular buffer

Posted: Mon Aug 08, 2016 12:28 pm
by Benj
Hi Zane,

At the moment we can't dynamically show/hide macros but this would be a handy feature for the future.

I'll think on your request and see if I can find a simple way to add the functionality without confusing things :D .

Re: Accessing data from within a circular buffer

Posted: Mon Aug 08, 2016 12:39 pm
by Zane
Hi Benj,

If you could find a way of doing that, that would be great. It would help simplify code. In the mean time the other way works too :D

Thanks

Re: Accessing data from within a circular buffer

Posted: Mon Aug 08, 2016 3:55 pm
by Benj
Hi Zane,

Have a go with this and see what you think. I've added the macro GetIndexedByte and it should return a value from the buffer without effecting buffer contents or pointers.

It should also fully work with the simulation.
CircularBuffer.fcpx
Flowcode 7 updated CB component
(66.85 KiB) Downloaded 352 times
Let me know how you get on, if this is ok then I will include it in the next update.

Re: Accessing data from within a circular buffer

Posted: Tue Aug 09, 2016 9:01 pm
by Zane
Hi Benj,

Thanks for taking the time to do this, i will try it out over the next couple of days and let you know how we get on.

Re: Accessing data from within a circular buffer

Posted: Mon Aug 15, 2016 11:43 pm
by Zane
Hi Ben,

I have tried this out and its working well, thanks for making this addition to the component. :D

Re: Accessing data from within a circular buffer

Posted: Tue Aug 16, 2016 10:18 am
by Benj
Thanks for letting me know,

You're very welcome.

Re: Accessing data from within a circular buffer

Posted: Wed Jan 04, 2017 9:59 pm
by maxtisc
Hi

This component Okay For FC6?
thanks

Re: Accessing data from within a circular buffer

Posted: Fri Jan 06, 2017 2:13 pm
by Benj
Hello,

No the v7 component will not work with v6.

Here is a component you can use with v6 with the extra component macro added.
CircularBuffer.fcpx
Flowcode 6 Updated CB component
(5.7 KiB) Downloaded 302 times