From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
04-14-2011 01:21 AM
Hello,
I have a question that the task of Buffer is to store the data and the queue is also of the same so could we use the Buffer inplace of queue in a Producer/Consumer Design Pattern.
Solved! Go to Solution.
04-14-2011 01:45 AM
You probably should explain what you mean by "Buffer". Thanks!
04-14-2011 01:58 AM
Except for the fact that a Queue kind of IS a buffer........
More explanation required.
Shane
04-14-2011 02:06 AM
Like one used here
04-14-2011 02:15 AM
smart buffer example.vi
04-14-2011 02:30 AM
No, those buffer examples are not nearly equal to a queue and will never ever "replace" queues in producer/consumer.
The most important advantage of queues for producer/consumer (which none of the other buffer mechanics share) is that it works eventbased to notify the reader that data is available. So if you would simply replace the queue by overly elaborate buffer mechanics as you attached to your last post, you will lose a great deal of the the purpose using producer/consumer.
So, to compare both mechanics:
- Queue works eventbased, whereas the buffer example does not.
- Queue has to allocate memory during runtime if more elements are written to the queue than dequeued. This is also true for the buffer (it has to be resized).
- Since the buffer is effectively simply an array with overhead, memory management is getting slow and messy with increasing memory fragmentation. Queues perform way better here (but have their limits there too).
- The overhead for the buffer (array handling) has to be implemented manually. Queue functions encapsulate all necessary functionality you will ever need. So queues do have a simple API, whereas the buffer has not.
- Since the buffer is simply an array, you will have a hard time sharing the content in two parallel running loops. You will need to either implement additional overhead using data value references to manage the buffer or waste lots of memory by using mechanics like variables. In addition to wasting memory, you will presumably run into race conditions so do not even think about this.
So this leads to four '+' for the queue and only one point where "buffer" equals the queue.
i hope, this clears things up a bit.
Norbert
04-14-2011 03:03 AM
Great thanks alot.
04-14-2011 10:22 AM
Well said!
Your buffer VIs are actually examples that ship with LabVIEW, however they are ancient! I would guess they pre-date the queue feature by a few versions and are thus quite stale. 😄