LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Frequently used string constant

What is the best way to use: Shall I transform frequently used string
constant to Global/Locals or not?

Mareike
0 Kudos
Message 1 of 6
(3,192 Views)
I think leaving them as simple constants is the best thing to do.

Globals and locals have overhead associated with reading them. In addition, you can be certain that a constant remains a constant, whereas a global or local CAN be changed by code (by mistake perhaps).

Shane
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 2 of 6
(3,192 Views)
Regarding re-usability of the constant in multiple positions of the code, you could create a very simple sub-vi which simply outputs the constant. This way you have the advantages of a true constant (can`t write) but also the ability to re-use the constant and most importantly auto-uptate all instances of the constant when you make a change to the "constant VI".

Shane
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 3 of 6
(3,192 Views)
There are few real constants in life. Except for pi or e or avogadro etc.
As for strings if it is not CR or LF I'd put it in a single place where you can change it for all it's occurences. If you don't like Globals, you could put it into a strict type-defined control and flag auto-update for it. But for small objects (not large arrays) the overhead for globals is small. I'd go for a global.
Gabi
7.1 -- 2013
CLA
0 Kudos
Message 4 of 6
(3,192 Views)
Gabriela,

I`m more or less familiar with the run-time properties of globals, but the phrase "for small objecty (not large arrays)" interests me. Perhaps I have forgotten some of the pros and cons of Globals (Or never knew it to begin with, which is more likely), but why is this?

Is the data copied when read from a global? How does this differ to locals, constants and so on?

I`m basically a person who doesn`t use globals if it can possibly be avoided.....

Shane
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 5 of 6
(3,192 Views)
I am not an expert either, maybe someone from overseas has deeper knowledge. In my opinion locals and globals are more or less the same, except of course for the different scope.
Their main disadvantage is that they break the data-flow concept and it is hard to track where their value changes. But still, sometimes living without, makes programs terribly un-elegant and clumsy.
As for Globals, writing a whole machine on labview as I do now calls vigorously for them, e.g. for storing configuration parameters that are used all over, but changed very seldom or just read in from ini-files. Distributing these via controls would make subvi's either look like porcupines or if combined into a cluster requires a (automatic) copy on entry to sub-vi's
of the whole trash.
Just again be careful where the value is changed.

For large data structures of course the memory allocation for every reference makes things more ugly.Yet still you could do a reference once per sub-vi and wire your way from there on.
Gabi
7.1 -- 2013
CLA
0 Kudos
Message 6 of 6
(3,192 Views)