01-22-2008 09:56 AM
01-22-2008 10:01 AM
01-22-2008 12:51 PM
01-22-2008 01:27 PM - edited 01-22-2008 01:28 PM
01-22-2008 02:10 PM
That appears to be a fair assesment, although the exact details are probably liable to change
jmcbee wrote:
It seems to me that if the input Array were large enough and the output array ended up being small enough that the while loop would be more efficient.
01-22-2008 02:13 PM
01-23-2008 01:28 AM
@jmcbee wrote:
It seems to me that there is a difference in the way that memory is allocated between the two as with the for loop a chunk of memory the same size as the input array is being set aside for the output array while with the while loop that chunk of memory is not set aside until the size of the output is known.
01-23-2008 02:18 AM
01-23-2008 08:00 AM
Saying much of the same but in my own words.
The For Loop has since LV 6.0 (or there-abouts) been able to allocate the buffer used for the auto-indec output tunnel one time before the loop starts.
The While loop CAN'T do this because it has no idea how big the array wil be. Therefore as the output tunnel array grows, the while-loop operation has to accationally stop and ask for more memory from the OS.
I also beielve I read somewhere that the condition to stop the For Loop is slightly more efficient than the explicit code required in the While loop. But I can not cite a reference to back up this belief.
Ben
01-23-2008 08:58 AM
Would just add that memory SIZE efficiency will not necessarily coincide with memory SPEED efficiency. Memory allocation operations can be very very very much slower than memory access / copy operations. In the RT world, they add a lot of jitter or indeterminism to your execution rate. The best choice will vary with circumstance, but in general I think there's more chance for a While loop to become inefficient than a For loop.
As a general rule of thumb, I'd probably use* a conditional auto-indexed For loop much of the time. With While loops, one can overlook degenerate cases and end up with an infinite loop. For loops are sure to be bounded.
-Kevin P.
* - haven't used one yet though. Still getting my feet wet in 8.5, and haven't yet needed the construct.