03-11-2011 03:46 PM
Hello,
I have been told that I need to remove all the local variables in my VI, because they are slow. I can not seem to find a good option for replacing them but keeping the same functionality.
What I am using the local variables for is to update 3 different graphs on the front panel from 3 different sources. Each of these sources are located in while loops so that data can be acquired asynchronously. In closing these 3 while loops is a case statement. The case statement is for switching between acquiring and saving the data or just acquiring data. The local variables are used to update the indicators and graphs from the acquiring and saving data case. It is these local variables that I need to remove.
Does anyone have any suggestions?
-- Z
03-11-2011 04:06 PM
Zurvan,
The procedure I usually use is to pop-up on the local and Find the Terminal. Then just run a wire from the terminal to whatever the local is connected to. Delete the local.
However, from your description of your VI it seems that you may need to get data from the while loops while they are still running. If that is the case you may need to use a queue or an Action Engine to transfer the data.
While loops inside a case structure sounds like trouble looking for a place to happen. Look at the Producer/Consumer Design Pattern to see if it might be more appropriate for your application. This pattern uses queues to move data between the two loops without needing locals.
Lynn
03-11-2011 05:12 PM
Lynn,
I am using the Queue to take in the data and then to write it out as a slower process. The local variables are just used for display and stopping the while loops. I don't use the local variables to store or transfer data between while loops. I will look at the Action Engine, but I am unsure if that is going to do what I want.
-- Zurvan
03-11-2011 05:17 PM
Are you sure that your speed concern is due to local variable? You can attach your code, so we can look at it?
03-11-2011 05:29 PM
I will see if I can get a release on the code or not, then a very striped down version that does not include all additional sub vi's that are needed for this VI. At last count there are over 30 sub VI's that I use.
03-12-2011 09:23 AM
From your description I tend to agree with jyang that the local variables may not be the cause of your slow performance. While there are probably better ways to do what you are doing with the locals, for those purposes you may not have much of a problem with race conditions.
Use the Profile Performance and Memory tool to help you determine where the bottlenecks are.
Lynn
03-12-2011 09:40 AM
A thing that may slow down a VI. May be poor designed array operations. And even mode bad are poor designed array operations combined with locale variables. But as mentioned use the profiler to which VIs that consume your time.
03-12-2011 12:45 PM
Zurvan wrote:I have been told that I need to remove all the local variables in my VI, because they are slow.
Who told you that?
As others have said, local variables typically don't cause slowdown (They cause additional datacopies in memory, have the potential of causing race conditions and cause messy code).
03-12-2011 02:43 PM - edited 03-12-2011 02:44 PM
Although the Locals may not be the culprits for the slowdown, you are still encouraged to remove them if possible. 😉
All kidding aside... Instead of guessing at what could cause the slower code, can you post what you have?
03-13-2011 10:04 AM
How often do you update the screen/display. Due to the limitation of the human eye. An updating frequency of about 20 times per second may appear as live and you can hardly see the difference from say updating at 1 KHz rate. In fact I think the 1 KHz display may produce more flicker. The trick is process data in chunk's. And cut down on the update rate of the indicators