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?
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.
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.
Are you sure that your speed concern is due to local variable? You can attach your code, so we can look at it?
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.
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.
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.
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).
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?
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