05-26-2009 09:25 AM
Hello,
I am programming a LabView VI based on an ActiveX from Horiba Jobin Yvon.
The Vi allows to acquire a 1024x256 pixels picture, or a part from it.
The program can run an acquisition a single time (single acquisition) or in loop (continuous acquisition), or triggered/driven by a measurement program.
Unfortunately, it seems that while acquiring the full 1024x256 pixels, the program can only run a given number of times before having memory issues. The problem appears to be correlated to the number of pixels being read...
Yet I have no experience about the memory management in LabView: when should one use local variables? What are the other alternatives when I have to modify a variable (typically in my case the graph) at different diagram position?
I cannot identify where my problem originates. And would appreciate any general or detaillled comment on this VI.
05-26-2009 10:07 AM - edited 05-26-2009 10:13 AM
Your problem is certainly with local variables and extremely inefficient code design. There is no need to use any local variables, but you seem to use them for everything, including large data structures, reading from and writing to them in tight loops. This escalates your memory use.
You clearly have a background in text based code and some old habits prevent you from writing efficient LabVIEW code. (see also).
All you need is shift registers. Let's look at one of your subVIs. (See image). You seem to be under the false impression that it is illegal for a wire to cross a structure boundary :o.
There is the terminal for "areas data" on the left, not connected to anything. Then, instead of simply wiring into the code, you first read it with a local variable to get the size and then you read another local variable instance of it with every iteration of the loop. Why? The control never changes during the execution of the loop! Right? Same with the orange 2D arrays. Initialize a shift regsiter, replace the data, and write to the indicator once after the loop has finished. No locals needed.
Also, why do you write to locals of all your scalar indicators? While this has no significant memory impact it doubles the complexity of your code. Simply delete the locals and place the indicator itself there.
05-26-2009 10:09 AM
Your code suffers from the dual-condition we here like to call "sequencitis" and "local variablitis". Text-based programmers would absolutely love your code. LabVIEW programmers, on the other hand, would have a heart attack. A quick look at it tells me that I could bet that 95% of your local variable are unnecessary, and I'm only holding out on the 5% since I'm not going to look at the code in detail. It hurts my eyes too much. Same goes for the sequence frames.
That said, your memory issues are probably caused by several issues:
I would stronly recommend looking into application design structures such as state machines. As it is your code is virtually impossible to maintain.
Couple of other comments:
05-26-2009 03:10 PM - edited 05-26-2009 03:11 PM
As another example, let's have a closer look at the VI "ShowAcquisitionOnChip.vi" that I quoted above.
I am sure this would be factors faster and would use significantly less memory. Of course it would only make a difference if you would refactor your entire application for consistent datatypes. Unfortunately, this will not be easy.
05-28-2009 02:22 AM
Hello,
Thank you very much for your comments! And sorry for the eye-pain & heart attacks I caused!
For some obscure reason I thought using local variable was a good idea. I am glad you corrected me on this point since I am still learning how to program in LabView.
I am currently in the process of rewriting the whole thing based on your comments. Hopefully this will kick out most of the issues I encounter.
Best regards!
Mathieu
05-28-2009 02:43 AM
It's no wonder you think Local Variables are good, as the same term is used for Good Programming in text based languages. Comparing with text based languages, you can view Wires as a pointer and a Local variable as a data copy. (Maybe not quite correct, but good enough as a rule of thumb)
Basically, both for performance and memory usage: Wires > Shift registers > Local variables > Properties
Situation ofcourse often dictates which needs to be used, but when you have the choice ...
/Y
05-28-2009 06:33 AM
Yamaeda wrote:
you can view Wires as a pointer and a Local variable as a data copy. (Maybe not quite correct, but good enough as a rule of thumb)
Basically, both for performance and memory usage: Wires > Shift registers > Local variables > Properties
Just a small change, wires as such are variables in LV & locals as data copies of those variables...
Mathieu,
To visualise what Yamaeda has said, just see the attached pic from LV Help, for efficient data passage.