07-12-2024 03:36 AM
I need to initialize an array of a fixed size (specifically, size 3) and populate it with three numeric variables (Numeric, Numeric 2, Numeric 3).
I understand that using the Build Array function might not be the most memory-efficient approach for this case. I want to ensure that memory usage is optimized while achieving the desired functionality. How can I do it? Thank you.
07-12-2024 03:41 AM
Hi Max,
handling an array of just 3 (fixed-size) elements doesn't involve memory handling so much!
I would just go with BuildArray: the compile KNOWS that you create an element of exactly 3 elements.
Everything else in your image just needs more block diagram space…
07-12-2024 02:17 PM - edited 07-12-2024 02:54 PM
@maxnoder1995 wrote:
I need to initialize an array of a fixed size (specifically, size 3) and populate it with three numeric variables (Numeric, Numeric 2, Numeric 3).
I understand that using the Build Array function might not be the most memory-efficient approach for this case. I want to ensure that memory usage is optimized while achieving the desired functionality. How can I do it? Thank you.
You are on a snipe hunt here and I am not sure why you even think that you need to initialize first, unless you also need the array values before placing the three numbers.
As has been said, the LabVIEW compiler is extremely smart, but here even a stupid compiler would immediately know the final size if you use built array with three inputs and will allocate accordingly. Right?
You need to trust the compiler and not try to overthink things. Once the diagram gets compiled and all optimizations applied behind the scenes, it will often no longer matter what you actually had on the diagram, so keep it as simple and readable as possible..
Any of your methods only work for very small arrays anyway (if you want to keep the diagram reasonable) and you should only worry about memory if you get into the millions. And even there you should only make sure you are not constantly resizing arrays in tight loops.
Typically, code should be scalable, so why can't you use an array of three elements as control??? 3x less diagram clutter! That's what I would do! And if you later need to modify to deal with e.g. four or five elements (or 10k!), no change in code is even needed!