04-04-2014 07:46 AM
Hi all
I am making a time critical labview code and trying to optimise it to the maximum extend possible. There are cases in which i need to buffer say around 50 elements and then analyse the pattern. I use shift registers for these. But they buffer all the values, from the start, where as i need only past 50 elements. I think, my code will run faster if this problem is solved. Is there any efficient method to store only the past n number of elements?
Thanks
Arya
Solved! Go to Solution.
04-04-2014 07:57 AM - edited 04-04-2014 07:59 AM
04-04-2014 07:57 AM
Arya,
a shift register only stores multiple values if you pull down the left side to display multiple elements. So a standard shift register stores only a single value. Period.
I assume that you have an array as shift register element and build up elements IN the array (using "Build Array"?). If so, you have to implement some code to limit the number of elements.
I recommend you to go for a circular buffer as concept.
Other option would be to use a queue limited to 50 elements.
Norbert
04-04-2014 07:59 AM
I'm guessing that you are appending your values to an array that is sent through the shift register.
What you would want to look at is fixed size queues. Drop an "Obtain Queue" before your loop, wire in your fixed size of 50 and the type you are using, pass this queue into your loop and populate it using the "Lossy Enqueue" function. This queue will contain up to 50 elements, and then always the last 50. After your loop, use the "Release Queue" function, which returns "Remaining Elements" which will be the (up to) last 50 elements in your loop.
04-04-2014 08:05 AM - edited 04-04-2014 08:08 AM
Hi
Thank you so much for the quick reply. I will try the methods suggested by you all. I am familiar with queue, but unfamiliar with circular buffers. I will read up about it and try that too..
@ M_Peeker, @ Norbert, thats right. I am using insert element into array for the same.
Arya