12-21-2009 02:50 AM
12-21-2009 03:26 AM - edited 12-21-2009 03:28 AM
HI ceties,
as usual there is a trade-off between speed and memory needs
To minimize buffer allocations you can use the traditional swap operation, here shown in text-based syntax:
swap(array;row1;row2)
{
help[]:= array[row1]
array[row1]:=array[row2]
array[row2]:=help[]
}
Your vi will need two buffers of size columns(array) and you could use "simple" IndexArray and ReplaceArraySubset functions. For your question you would call swap two times: swap(array;3;4) and swap(array;2;3) in exactly this order...
And yes, right now the InPlaceStructure doesn't support to work on columns/rows in place - you have to index single array elements. But there is an idea in the exchange to vote for...
12-21-2009 08:31 AM
Take a look at the application->memory control palette there are some very under-utilized structures for moving memory locations in place.
01-08-2010 05:04 AM - edited 01-08-2010 05:07 AM
Hi Gerd andthanks. You are right with the trade off between speed and memory allocation -the swap operation is thus not very useful – just imagine I was moving the line 2,3 not to instead of 4 but lets seto 99 – the amount of swap operations would be enormous.
If somebodyis interested why I needed that here is why
2 falkpl:There is nothing that would help on that palette. Hopefully in the futurereleases.
01-08-2010 11:50 AM
ceties wrote:
Is it possible to do it without deleting the row and inserting it to new position since that causes memory deallocation/allocation?
Yes, since the array does not change size, operations can be done in place, and all you need is a buffer for a single row, a loop, and the 2D array in a shift register. You only need to touch rows 2-4.
Another option would be to keep the 2D array untouched and just manipulate a lookup table of row indices. It really depends on how it's used and what you need it for.
In any case, these methods will be orders of magnitude more efficient than delete from array + insert into array.
How big are the arrays and how often do you need to do all this?
01-11-2010 05:34 PM
Lookup table – I considered that but I would have to significantly alter the code of the application and one slight mistake would lead to a disaster (user would see different data than chosen in Listbox)
Swap the rows - what if I wanted to move the line 2,3 not instead of line 4 but lets say instead of line 99? – do you really think it would be faster than deleting and inserting? Swapping approach would lead to hundreds of line swapping operations if I count right. Or did I miss something?
The array is usually 20x3x3600 DBL. The operation is based on user interaction (Drag&Drop) and only once a while. Thanks for suggestions.
01-12-2010 02:25 AM
I don't think you get the point of a swap - it's not that you swap one row for the next until you get to where you want. You simply take the row you want and replace the target row with it. This will create two additional buffers (one for each row), but the large array should remain the same.
The in-place element structure will not be useful in this case, since it can't replace rows. I believe Altenbach has an idea for that in the exchange, so you can go vote it up there.
01-12-2010 07:01 AM - edited 01-12-2010 07:04 AM
I definitely get the point of swapping but the problem is that pure swap doesn’t do the thing here. Imagine you have rows as follows:
0
1
2
3
4
5
6
7
8
9
I take rows1,2,6,7 and I want to move them behind the row 4 so I get the sequence
0
3
4
1
2
6
7
5
8
9
I am satisfied with my solution I was just wondering if there is some better since I was aware of slight memory unfriendliness of it.
01-12-2010 07:36 AM
I see. That's a different situation, because you have to move multiple elements.
Here are four options I can think of:
01-12-2010 08:31 AM