LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to retain data in subVI for next run

Solved!
Go to solution

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)? 

0 Kudos
Message 1 of 11
(5,734 Views)

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

Message 2 of 11
(5,715 Views)

http://forums.ni.com/ni/board/message?board.id=170&message.id=240328#M240328

 

Action Engine is superb 

Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
0 Kudos
Message 3 of 11
(5,712 Views)

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.


___________________
Try to take over the world!
0 Kudos
Message 4 of 11
(5,703 Views)

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

0 Kudos
Message 5 of 11
(5,690 Views)

Functional Global.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

Message Edited by Baji on 05-26-2009 03:09 PM
Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
Message 6 of 11
(5,687 Views)

Hi,

I got it.  Thanks.

Does this use less memory than local variables?

regards,

Apurva

0 Kudos
Message 7 of 11
(5,677 Views)

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

 

 

 

 

Message Edited by Baji on 05-26-2009 03:32 PM
Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
0 Kudos
Message 8 of 11
(5,671 Views)

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.

- Partha ( CLD until Oct 2024 🙂 )
Message 9 of 11
(5,669 Views)
Solution
Accepted by topic author Apurva_Sen

Hi Apurva,

 

See the attached screenshot from the LV help for memory efficiency of various data passage elements of LV.

- Partha ( CLD until Oct 2024 🙂 )
Message 10 of 11
(5,647 Views)