03-17-2008 10:31 AM
03-17-2008 10:41 AM
I'm not sure whether there are differences in efficiency between these tow approaches... However, I think that any difference in efficiency would be outweighed by the importance of a good software architecture. If there are subsets of global data that for some reason must be stored in global variables, it may simplify the design to cluster them together. For example, maybe you have one set of data that you need for trace logging purposes, and another that you need for configuration data. I would argue that it would be worth organizing them into two global clusters regardless of efficiency.
Anyway, hope that helps,
Rob
03-17-2008 10:49 AM
Hi,
Can you give us more details about your application?
By the way, when you read from a global variable, LabVIEW creates an extra copy of the data stored in every global variable you use in a VI. Reduce the number of global variables to improve the efficiency on performance of VIs. Basically, creating copies of the global variable takes up memory resources on your PC.
03-17-2008 11:46 AM
03-17-2008 12:00 PM
03-17-2008 12:24 PM
03-17-2008 12:40 PM
If I used Globals (IF) I would not lump them together into a single data structure (like cluster or array) due to the demands it would put in my appliciaotn to use semaphores (or simlar) to protect the data from race conditions.
Also if the data is not related it is also a bad idea to lump unrelated items together. This eventually leads you into the "Super Cluster" problem were changing a single bollean require a masive amount of memory (to store all fothe copies) and CPU to feed all of those copies.
I'd go with the previously suggested Action Engine approach.
Ben
03-17-2008 12:52 PM
I agree that an action engine seems more efficient since LabVIEW only knows how to update the whole %!$! cluster of a global data structure. (That is, I don't think there is a way to just update one item in a cluster of a global as you could in say, C++. Instead you have to 1) read the global cluster, 2) update the item you care about, 3) write the WHOLE thing back into the global. While this is inefficient, keep in mind that it is very easy to write an action engine VI that is just as inefficient. Nevertheless, if it is done well, an action engine will probably improve things.
Nevertheless, I think one thing you should definitely consider is whether you need globals at all. Globals are a bad idea 99% of the time. Sometimes they can be used to a good end, but usual they represent an easy way out that eventually makes things more difficult.
Rob
03-17-2008 01:01 PM
03-17-2008 02:11 PM
That is the purpose of the connector pane in your VIs. You can use the connector pane to define inputs and outputs for your subVI. Then, when you call the subVI from another VI, you can wire the data to the appropriate terminals. There must be a simple LabVIEW basics tutorial online that you can follow along with. You need to know this stuff if you plan on writing code that doesn't drive you insane.
Rob