LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
rcpacini

Replace Array Subset with Insert Into If Not Initialized

Status: New

I didn't find a post on this but i could be mistaken. It would be nice if there were a selection on the Replace Array Subset to Insert data into an index that may not be initialized. The work around is simple therefore the functionality should be easy to add. I know most will argue that this is a waist of development time but it was worth throwing the idea out there.

 

20455i9FFBD25F46FF35F9

2 Comments
altenbach
Knight of NI

Well, one of the important features of "insert into array" is the fact that it operates "in place" and is thus very memory efficient. This also requires that the array size does not change. The programmer needs to simply make some effort that the array is of sufficient size from the beginning. If you are not sure about the final size, initialize once to a reasonable upper limit and trim it at the very end if really needed.

 

I don't think we need your suggestion. It simply leads to sloppy programming.

 

Your workaround is actually (1) overly complicated and (2) fails to deal with the situation where the inserted element is an array itself. Here's alternative code for these two conditions that seems a bit simpler if you really feel the need to do hidden resizing. Simple enough? I think so! 😉

 

jmorris
Active Participant

I run into this problem a lot with my functional global variables, where I have an uninitialized shift register with an array on it.  Especially when for defaults I just want the default value of an array, but I obviously cannot initialize it in the normal way, it is frustrating to have to add extra code to do what seems like it should be the default behavior.  I usually end up using the First Call? VI with a case statement to either create a new array (if true) or pass through the existing one (if false).

 

I realize that inserting loses the memory efficiency of operating in place, but that would only be true when the index does not already have a value in it; thereafter it would revert to the old behavior.  And just because a VI has a built-in workaround for an unusual condition does not make it sloppy code; I would argue the same idea applies to the fact that indexing outside the bounds of an array gives you a default value instead of uninitialized memory.  Sure, NI could force everyone to do a boundary check on your array before indexing it, and most code will include this anyway, but if you know the defined behavior of the built-in VI in unusual conditions and can use it to simplify your code, I don't see that as bad programming.

 

My 2 cents; I really like the idea and gave Kudos.