07-17-2008 09:42 AM
07-17-2008 10:49 AM
No promises here, just some thoughts.
At 1 M/sec you'll need to be a little careful with your memory handling. If you send your array straight from your DAQmx Read into a queue with no other branches, LabVIEW is smart enough not to copy the 1 M/s of samples. It lets the queue own the memory pointer. Then when your File Writing code performs a de-queue, once again LV won't need to do a memory copy of all the array elements.
However, if you want to send any of the data elsewhere such as a live user display, there *will* be some data copying going on. You'll benefit from a good strategy on this. Others may provide better or more proven ideas, but meanwhile here's what *I'd* do:
I would let the File Writing code take a subset of the data it pulls from the queue and send it out for use by the User Display code. I would use a Notifier rather than a Queue for this, as it probably isn't crucial if the live display misses an occasional frame. This approach allows the data acq to collect and enqueue at the max rate you need. If this data copying bogs things down occasionally, the Queue just buffers data for a while until the File Writing code can start catching up. The data acq won't be slowed down.
-Kevin P.
07-18-2008 08:08 AM
07-18-2008 10:53 AM - edited 07-18-2008 10:54 AM
I don't know the definitive answer, but I'd start by sending the data *after* it has been written to file. There may be a way to structure the code to give LV enough hints that it won't ever have to make an actual data copy that way. From reading other threads, I've come to understand that doing an array subset operation does not necessarily result in data copying.
So if the file write is done and *then* a subset of the written array is passed to a Notifier, LV may likely realize that the Notifier can now simply take over ownership of the original chunk of memory rather than making a copy of the contents. I suspect (but am not at all sure) that if you branched the data off to a Notifer *before* the file write, a data copy would need to happen.
Attached is a screenshot to illustrate the kind of hint I have in mind. Putting the notification inside a single-frame-sequence structure helps tell LV that the write must complete execution before performing the array subset and notification. That should be enough hint that it can give owenership of the array to the Notifier.
-Kevin P.
07-19-2008 03:07 PM
Notifiers always make a data copy at the Send Notification node. The reason is that you can obtain a notifier and then ask to get the latest notification even after it occured, so it needs to exist somewhere. I don't have the specific reference on me, but it should be in one of Stephen's posts on LAVA.
A queue does reuse the buffer because the data can only be dequeued in one place, so you would want to use a queue here.
07-20-2008 01:19 AM
07-21-2008 08:05 AM
Thanks for the correction, tst. Yeah, it *does* make sense -- if you were to loop over Wait On Notification with "ignore previous" = True, you'd *expect* to keep retrieving the same stale data.
I think it'd still be my preferred option though, since the data copy would be confined within the GUI chart update code. If I had decided I could live with lossy notifications, I could very likely also live with a little extra lag in the display. There are other kinds of apps that would be better served by using queues.
-Kevin P.
07-21-2008 11:29 AM
07-22-2008 07:37 AM
Hi Kevin,
I followed your suggestion and used the notification to display the array subset. If the subset will copy the data in any case, then I don't need to add a single-frame sequence for that, is that correct? And another problem is, I want to display some subsets of the array but not just one, for it's a long array and the displaying didn't update fast enough. Do you know how I can do that? Thank you for your reply.
Best wishes
Bo
07-22-2008 08:00 AM