LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

creating multiple constants

Solved!
Go to solution
Does creating and using multiple constants (string or numeric, say instead using of two numeric constants, conating same value, at two stantdifferent locations in the same VI, if I use one constant as common) affects anywaym on performance or memory consumption? What if the constant is big array?
0 Kudos
Message 1 of 6
(3,760 Views)
Solution
Accepted by topic author pritam

I'm not sure what you're asking here, but each constant on the block diagram clearly requires it's memory space for storage. The more constants you have, the more memory is required. It oughn't affect performance, however, unless you're talking about several hundred megabytes of constant data being passed around.

 

Besides - is there any alternative? When you need a constant, I can't imagine there's a more efficient manner of providing one than to use one?

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 2 of 6
(3,758 Views)

FYI Thoric

See the attched image.

 

Thanks for your reply.

0 Kudos
Message 3 of 6
(3,750 Views)
I have to admit I'm still not entirely sure what you're asking, but the image you attached discusses some very small constants. The memory allocation for each of these is negligible (a few bytes), and the performance impact impossibly insignificant to determine. I really wouldn't worry about it.
Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 4 of 6
(3,748 Views)

From your pic, YES!

 

It is better to use a single constant by placing it outside of case structure and/or loops (for/while), if the data is going to be the same.

 

We need to program this way, whether or not the constant is big or small (from memory perspective), just for the sake of easy understanding of the program itself.

 

Constants with big data set will definitely hinder performance because they will get included in the code memory multiple times if present in multiple locations.

- Partha ( CLD until Oct 2027 🙂 )
Message 5 of 6
(3,721 Views)

Another advantage of using one constant and wiring it to multiple places is that if it ever needs to be changed, the programmer only has to find and change one location.  If the constant was in ten or twenty place in the program and one or two were missed during a change, consider how difficult it might be to locate the error, or even to determine that an error existed!  Partha's comment about placing it outside the structure also contributes to ease of maintenance by making it easier to find the constants.

 

Lynn 

0 Kudos
Message 6 of 6
(3,706 Views)