11-22-2011 07:49 AM - edited 11-22-2011 07:52 AM
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.
11-22-2011
07:57 AM
- last edited on
05-30-2025
07:24 PM
by
Content Cleaner
@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.
11-22-2011 09:40 AM - edited 11-22-2011 09:40 AM
@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.
11-22-2011
10:43 AM
- last edited on
05-30-2025
07:25 PM
by
Content Cleaner
You could also use data value references, single process shared variables, or a simple action engine. The possibilities are endless. 🙂