06-04-2009 08:40 AM
When using shift registers you keep your data in the big 2D array. Replacing single elements is done in place (no memory allocated).
When using auto-indexing the 2D array is basically split into rows and then re-assembled. The replace on the single row is also done in place, but splitting and reassembling the big array is inefficent I think.
What surprises me is if you display memory allocations it looks the same for both methods.
06-04-2009 08:46 AM
This example seems to be a bit faster.
Your re-sizing can't be done in-place so it's best to simply accept the one data copy and minimise other copies on the same data set.
Shane.
06-04-2009 09:02 AM
Now you need a copy of a portion of your data.
An alternative to Shane's solution is to rotate the array.
See attachment.
From the point of data handling it would be easier and faster if you would split the 2D array in 4 1D arrays. The code will be less scalable, but if the size is fixed (4) then it might be worth it. In this case you always operate on 1D arrays and can do everything in place.
Daniel
06-04-2009 09:06 AM
After some look around, I just found a link which gives logical reasoning for Shift Registers being faster than Loop Tunnels.
http://udc.adicenter.com.cn/download/tutorial.pdf
Page 4 and 5 gives the reasoning to the working methods of SR and LT.
Ritesh
06-04-2009 09:11 AM
Hi daniel,
i just ran ur code and found it a bit slower than the one suggested by Intaris.
While ur code takes about 11-12 ms on my machine, Intaris code took 8-9 ms to complete the operation.
Ritesh
06-04-2009 09:22 AM
Have you checked the funcitonality?
I put it together rather quickly so it may not be doing what you require of it.....
Shane.
06-04-2009 09:33 AM
Intaris wrote:Have you checked the funcitonality?
Yes, its doing exactly the same thing.But i didnt understand 1 thing in ur code. u r using Build array function the for loop. and as per my understanding, build array function always makes another copy of the output array.now i was just keeping an eye on the memory using memory profile and noticed that it took same amount of memory if i ran the loop for 100 or 200 times.Ritesh
06-04-2009 10:53 AM
The array (60000 entires) is being copied ANYWAY. I'm just stcking another 200 entries ont he end of it before truncating again.
The only memory difference is the 200 entries intotal. It doesn't accumulate per loop, it's released after each loop iteration.
Shane.
06-04-2009 03:28 PM
Intaris wrote:The only memory difference is the 200 entries intotal. It doesn't accumulate per loop, it's released after each loop iteration.
Ok. I didn't know that LV releases the memory occupied by Build array function after the loop is terminated.
Just had the idea that it keeps accumulating it.
Ritesh