LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

local vs. global variable

I remembered some document on memory management with LV.

As a rule of thumb, local and global variable is not so good in terms of  memory management.

But I realized real programming is quite difficult to follow this rule (actually, in using separate loops like producer conisumer structure.).

 

I have to manage a big array of DBL in many logics in the producer loop, though I know I have to use the shift register.

 

Whenever I used the local variable of array, the memory will be consumed twice or three times.

However, I am wondering if there is a different between global and local variable, or functional global. 

Can you compare these things (local, global, or other I didn't use) in terms of memory and speed performance?

 

labmaster.

0 Kudos
Message 1 of 4
(3,828 Views)

@labmaster wrote:

I remembered some document on memory management with LV.


Perhaps you are referring to this: https://www.ni.com/docs/en-US/bundle/labview/page/memory-management-for-large-data-sets.html, which is in the LabVIEW Help.

 


As a rule of thumb, local and global variable is not so good in terms of  memory management.

Not completely accurate. The issue is to reduce the number of copies of the data. Local and global variables have their use. And abuse.

 


But I realized real programming is quite difficult to follow this rule (actually, in using separate loops like producer conisumer structure.).

Then may I humbly suggest that you are not doing "real programming". Honestly, what do you expect from statements like this? A good architecture and program is not dependent on the use of local variables and/or global variables. Consequently, the use of local and/or global variables does not mean you have a crappy architecture or program.

 


I have to manage a big array of DBL in producer loop.

Whenever I used the local variable of array, the memory will be consumed twice or three times.

However, I am wondering if there is a different between global and local variable, or functional global. 

Can you compare these things (local, global, or other I didn't use) in terms of memory and speed performance?


You should be using a queue. That's the basis of the producer-consumer architecture.

Message 2 of 4
(3,820 Views)

@labmaster wrote:

But I realized real programming is quite difficult to follow this rule (actually, in using separate loops like producer conisumer structure.).



Nothing could be further from the truth. Assmercurio_fc stated, a good architecture and design will alleviate the need to rely on local and global variables. I would even argue that it is quite easy to never use a global variable. In fact, I haven't used one since the mid 90s. Even then I tried to avoid them and used them very rarely. When I use local variables they are almost always restricted to my UI code in order to read from an indicator or write to a control. And when used the necessary controls are in place to eliminate race conditions.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 4
(3,798 Views)

You could also use data value referencessingle process shared variables, or a simple action engine. The possibilities are endless. 🙂

0 Kudos
Message 4 of 4
(3,780 Views)