Accessing data from within a circular buffer

Please add any feature requests for Flowcode version 7 here

Moderator: Benj

Post Reply
Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Accessing data from within a circular buffer

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Accessing data from within a circular buffer

Post 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.

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Accessing data from within a circular buffer

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Accessing data from within a circular buffer

Post 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 .

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Accessing data from within a circular buffer

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Accessing data from within a circular buffer

Post 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 344 times
Let me know how you get on, if this is ok then I will include it in the next update.

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Accessing data from within a circular buffer

Post 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.

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 93 times
Been thanked: 76 times
Contact:

Re: Accessing data from within a circular buffer

Post by Zane »

Hi Ben,

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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Accessing data from within a circular buffer

Post by Benj »

Thanks for letting me know,

You're very welcome.

maxtisc
Posts: 110
Joined: Mon Dec 23, 2013 9:34 pm
Has thanked: 2 times
Been thanked: 9 times
Contact:

Re: Accessing data from within a circular buffer

Post by maxtisc »

Hi

This component Okay For FC6?
thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Accessing data from within a circular buffer

Post 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 299 times

Post Reply