LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the difference between putting all the objects into one Global Variable and using one Global variable for each object?

Is there any advantage/disadvantage between using one Global Variable  for all the objects and one Global Variable for each object?



0 Kudos
Message 1 of 12
(3,867 Views)

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

0 Kudos
Message 2 of 12
(3,861 Views)

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.  

    Benjamin R.


Senior LabVIEW Developer @Neosoft


Message 3 of 12
(3,853 Views)
Why do you want a Global Variable for each object?
0 Kudos
Message 4 of 12
(3,828 Views)
Thanks Benjamin R and every one else who responded to my question.

I am just trying to decide what the best practice is when it comes to using Global Variables.

I am just having quite a few values to pass between VI's, e.g. Boolean, Numerical, Strings, etc.

Thanks for the help again.
0 Kudos
Message 6 of 12
(3,809 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 12
(3,801 Views)

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

0 Kudos
Message 8 of 12
(3,794 Views)
How do I communicate data between VI's if I opt to not use Globals?
Message 9 of 12
(3,787 Views)

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

0 Kudos
Message 10 of 12
(3,773 Views)