06-12-2012 04:32 PM
It will stick... that's why I initialize it outside the while loop, so I use the same array over and over. I've been doing this for years and it works. I just want to know if there is something in the code that might make LabVIEW make a new copy and put it elsewhere.
06-12-2012 04:34 PM - edited 06-12-2012 04:35 PM
I guess I don't know your definition of "stick". 😄
Where is "elsewhere" and how do you tell?
06-12-2012 04:38 PM
By stick I mean the array is defined in memory and always stays where it was originally defined. Elsewhere would be anywhere other than where it was originally defined. How can I tell? That's my question. I mean, when it works I can tell that it's staying put. This, however, is not working, and so I'd like to know if there is a way to test where it is stored in memory from one iteration to the next.
06-12-2012 04:51 PM - edited 06-12-2012 04:51 PM
If you want to start with a blank array with each iteration of the loop, do what you currently do. If you want to retain the updated values, the array needs to be kept in a shift register.
06-12-2012 04:59 PM
Won't that force copies to be made in my sub vi because I'd then have to use an output array?
06-12-2012 05:09 PM
@rickford66 wrote:
By stick I mean the array is defined in memory and always stays where it was originally defined. Elsewhere would be anywhere other than where it was originally defined. How can I tell? That's my question. I mean, when it works I can tell that it's staying put. This, however, is not working, and so I'd like to know if there is a way to test where it is stored in memory from one iteration to the next.
I don't think there is a way for you to tell where LabVIEW stores the array in memory. One of the features of LabVIEW that I really appreciate is that I don't have to worry about the low level things such as memory allocations that I do have to worry about when writing C.
The only thing I can think of where LabVIEW would move a an array to a different location is if you add something and it requires a new allocation because the current one is too small.
Why does it matter where the array is?
06-12-2012 05:13 PM
It doesn't matter where it is. I just don't want to be making copies over and over. I want to, if possible, use the same array over and over and only replace one element per iteration. Creating a new array and copying over the contents takes time.
06-12-2012 05:23 PM
If you put it in a shift regsiter, it is kept in exactly one location. You can read from that location on the left, modify the array, then write the changed value back on the right.
06-12-2012 05:30 PM
Another good candidate for a shift register is the rate index. You can also use a feedback node if those existed in LabVIEW 7.0.
06-12-2012 08:21 PM
7.0 has feedback nodes.
I see that a shift register would work if I was modifying it directly, but I'm passing it to a sub vi. In the calling vi, I would initialize the shift register. I would pass the left side shift register to the input of the sub vi and pass the output of the sub vi to the right side of the shift register in the calling vi. Here's my question... If I use an array variable as the input to the sub vi (as it is now) and put the modifed array into another array variable as the output from the sub vi, will, inside the sub vi, the input and output array be the same array as the shift register, or will it all be copies? Thanks.