I looked for a similar idea, but I didn't' find anything. I find that hard to believe, so I may have missed it somehow.
LabVIEW has arrays the dynamically grow. This is great. Love it. It makes it very easy to do things like Loop A below.
But that can lead to performance issues as LabVIEW constantly has to allocate new memory as the array grows. However, and this is important, LV is smart enough to over allocate so that not every append results in new memory allocation. Somewhere in the LV code NI is keeping track of the size allocated and the size used.
If performance is a concern, we've always been told to do something like Loop B. Preallocate a big array and use Replace. But there are problems here. First, a lot of the built in array functions will return 'wrong' values (Array Size, etc.). Second, what if the initial size is just a best guess. If we need something larger (say 5050 elements), we have to have a special case to Append instead of Replace once we hit the initial allocation. BUT, LV is already doing all this internally, it just isn't exposed to us in a way that we can take advantage of.
So, I propose Loop C. (sorry, too lazy to create a good icon). This new primitive would return an empty array (like Loop A), but with memory already allocated for a much larger array (like Loop B). LabVIEW already has the code to handle this. So, if we know the array will grow to ~5000 we can preallocate that amount, have all the built in functions work and not have to worry about going over 5000.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.