05-26-2009 01:59 AM
Hi,
I am reading a csv file and passing data read from the file as arrays (approx 170000 elements). I am processing the data in a subVI. I call the processing subVI several times from the main VI. Since it takes a long time to read the file every time. I am storing the arrays in local variables and when I call the subVI next time, I read the data from local variable instead of reading from file. This has reduced the execution time manyfolds. Since the applocation is not facing memory crunch right now, I don't face any problem. But I am not sure what happens when the application runs on system with lesser RAM. Will the local variable be deallocated (thus making the applications unusable) or will it throw memory full error?
Is there any other better way to store data in subVI which can be used next time when it is called (without passing all the data to main VI)?
Solved! Go to Solution.
05-26-2009 03:28 AM
Hi Apurva_Sen,
an Action Engine should help you. You only need to read the data ones and store it in a shiftregister. See Bens nugget for more information about it.
Hope it helps.
Mike
05-26-2009 03:40 AM
http://forums.ni.com/ni/board/message?board.id=170&message.id=240328#M240328
Action Engine is superb
05-26-2009 04:08 AM
I'm guessing from your question that you're coming from a text-based background. It's important to note that the term "local variable" is misleading. A local variable in LabVIEW is actually a secondary access point to the value of a control or an indicator. When you use one, an extra buffer is always allocated for its value (although it's only allocated once for each local variable in the diagram, assuming the size of the data doesn't change).
This, however, is rarely the real issue with them. The main issue is that because it's very easy to write parallel code in LabVIEW, it's also very easy to create race conditions, particularly when using local or global variables with multiple writers. In general, you should try to use wires to pass data around as much as possible. When you have parallel code and can't use wires, dynamic events, action engines, notifiers and queues tend to cover most of what you'd need.
05-26-2009 04:30 AM
Hi,
I saw Ben's nugget. Action Engine(AE) uses shift registers(SR) as storage element. Since my subVI doesn't have any loop, I'm not able to use SR. One possibility is that I use a loop which runs only once and contains everything in that subVI. But I don't know if it is a good practice. Please suggest.
Is there any difference between using a SR Vs local variables w.r.t execution time and memory usage?
regards,
Apurva_Sen
05-26-2009 04:36 AM - edited 05-26-2009 04:39 AM
Creates an action engine.It is an VI which contains two cases (Set and GET) with unintialized shift register,In the Set case read your file and put the data in the shift register and acess the data where ever u want from the GET case.It is anIndividual VI dont need to change ur programme architecture
05-26-2009 04:49 AM
Hi,
I got it. Thanks.
Does this use less memory than local variables?
regards,
Apurva
05-26-2009 05:01 AM - edited 05-26-2009 05:02 AM
Ya It also takes memory to hold your data.using local variables u can only access the data with in the VI, but using Function Global u can acess the data any where.each has its own advantages and disadvantages.Read Bens nugget for more infos http://forums.ni.com/ni/board/message?board.id=170&message.id=240328#M240328
05-26-2009 05:02 AM
Apurva_Sen wrote:
Since my subVI doesn't have any loop, I'm not able to use SR.
One possibility is that I use a loop which runs only once and contains everything in that subVI. But I don't know if it is a good practice. Please suggest.
Is there any difference between using a SR Vs local variables w.r.t execution time and memory usage?
For the first statement, the answer is, you can use a Feedback node outside of a loop, if you have LV 8.5 or later.
For the second, Yes, it is still good to use a loop that runs just once.
For the third, I think tst's explanation is detailed enough. You can search these forums for the title, "difference between wires, locals & property nodes"; you ll get soe good old detailed discussions reg the same.
Normally, data carried around by a wire is approx 200-300 faster than using locals which in turn is again some hunderds of times faster than that of the Value property node.
05-26-2009 05:13 AM
Hi Apurva,
See the attached screenshot from the LV help for memory efficiency of various data passage elements of LV.