Jump to content

A simple method to buffer input


Recommended Posts

I find myself frequently looking for a good pattern for collecting a pool of array elements until they reach a certain size and then removing the oldest elements first. I have used very stupid methods like a bunch of feedback nodes being fed into an build array node. But today I thought up one that I really enjoyed and I thought that I'd share it. Its a simple pattern and no crossing wires :). Perhaps someone has thought of something better, if so don't hesitate to share.

Example_VI_BD.png

Link to comment

Very neat and postage stamp sized.  There are apparently lots of different ways to perform this and I have yet another way that I've been doing.  This is part of my Force 1D Array Min or Max Size VIM that is part of my array package found here.  I am curious what is the fastest, and under what conditions one works better than another.

Force 1D Array Min or Max Size.png

 

Also somewhat relevant is my Circular Buffer XNodes I made here.  This one uses the shifting method, but tried to be a little more efficient with things like not shifting if it wasn't needed, and if a shift was needed to keep the shifted data so a consecutive read wouldn't require a shift or split and build.

Link to comment

So I did a quick run, and I probably need to state that the above methods cannot really be compared apples to apples. Partially for the following reasons:

  • Some methods only support one element at a time input. If you need to enter 1000 pts at once these methods will probably be slower and involve more operations.
  • Some methods like the circular buffer are much more useful in certain situations like where the buffer is needed in different loops or are acquired at different rates. 

here are numbers for single point(one element at a time) inputs:

How long does it take to process 10000 input samples with a buffer size of 1000 on my computer?: 

  • Taylorh140 => 8.28579 ms 
  • infinitenothing => 2.99063 ms  (looks like shifting wins)
  • Data Queue Pt-by-pt => 9.03695 ms (I expected that this would beat mine)
  • hooovahh Circular Buffer => 8.7936 ms (Nearly as good as mine and uses DVR)

I would consider all these to be winners, except maybe the Data Queue pt-by-pt (but it is available by default which gives it a slight edge), Perhaps ill have to do another test where inputs are more than one sample.

Note: if you want to try the source you'll need the circular buffer xnodes installed.

buffer.zip

  • Like 1
Link to comment

How often you write new elements versus how often you have to read the whole array may also skew the preference given to one scheme. For example, if you write often a single element, just replacing it in place at (i mod N) may be efficient, whereas the readout which involves an array copy may be left with a more expensive solution. This is my go at it, not double checked, may be bugged.

w.pngr.png

  • Like 1
Link to comment
  • 4 years later...
53 minutes ago, Jared Breiter said:

What would these types of buffers be called? I see that these and circular buffer are both FIFO, but the array in a circular buffer is not in time order (the index of the recent value is last vs: always moving right?)

In the case of a circular buffer your "get data" method would deal with the wrap around so would return to the caller data in time order (otherwise what would be the point).

This is a nice use case for a class as you don't really want to expose the implementation to the calling code.

I have something like this

image.png.4e07f73e9e9048f462925b17e3c10342.png

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.