LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to quickly clear an array used in a shift register?

Solved!
Go to solution

Hello all,

 

I'm sure this is a quick one, but I'm missing the concept.

 

I have an array of boolean in a shift register. I have a case where I need to basically 'reset' the array rather than append to it....what is the best way to do this?

 

Thank you,

 

cayenne

0 Kudos
Message 1 of 6
(4,828 Views)
Solution
Accepted by topic author cayenne

Use an empty boolean array constant to clear your array.

 

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
Message 2 of 6
(4,824 Views)

Except for your word "append", it is not really clear what you mean by "clear" an array". It seems you want to reset the size to zero elements.

 

(Efficient and well written programs typically keep fixed-sized array in shift registers, so a reset could also mean set all elements to FALSE.)

 

Here's code for both interpretations. 😄

 

Message 3 of 6
(4,812 Views)

Christian,

 

I was curious about the relative efficiency of using Reshape Array vs. an Array Constant to resize an array to zero so I made a benchmark program. In the process, I stumbled onto something unexpected. It appears that using Reshape Array with a dimension size of zero is significantly slower than when specifying a dimension size of 1 or more.

 

Testing with an Array Constant used 4 blocks of memory vs. 6 for the Reshape Array version.

 

LV2010 SP1

 

Of course, it is possible that my benchmark program is flawed.

 

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
Message 4 of 6
(4,788 Views)

@stevem181 wrote:

Of course, it is possible that my benchmark program is flawed.


Yup, disable debugging and you will see that the inner FOR loop is folded in both cases and the time drops to about zero.

 

 

Testing with debugging enabled is potentially unfair, because the reshaping will have more debugging code because there are more potential places to probe a wire, for example. All that said, I don't really know what's more efficient. That would require much more sophisticated testing. My point was just a reminder that there are always many ways to do things.

 

(This is under LabVIEW 2012. Constant folding and dead code elimination of course differ between compiler versions)

 

Granted, I typically don't use any of these two versions: I also omit the diagram constant, set the tunnel to "use default if unwired" and keep in unwired in the "clear" case. 🙂 Less diagram clutter and quicker coding. 😄

 

Here's how it would look like.

 

Download All
Message 5 of 6
(4,772 Views)

Trying to prevent folding on the inner loop, I came up with the following code. I don't know if it is sound, but things remain really fast (debugging disabled), but folding no longer shows.

 

 

 

You need to set the iteration on the outer loop to 100M (1e8) to even see a measurable delay. I see the following times:

 

75ms reshape

65ms diagram constant

65ms unwired and use default

 

This suggests that we don't have to worry about performance here. Clearly, the compiler still does some magic which I don't fully understand. For example if you would wire the array across unchanged on both cases of the case structure, the code slows down by a factor of about 30x. Why?? (Yes, the SR and output tunnel carries more data but ...)

 

I stick to my statement that "unwired&use default" is the cleanest option.

Message 6 of 6
(4,764 Views)