Exist better way how moving elements inside array?

 

Hi guys,

Example: I have 1 array ArrayTest [10] [10000] and I need move whole 4th row to 2nd line (rewrite data inside array)

My code:

for(int j=0; j<10000; j++)                  
  ArrayTest[2,j]=ArrayTest[4,j];  // I must move each elements from 4th row

 exist some better way? Main parameter for me is speed operations.

Is possible move whole row inside array? Thank you.

 
endy5:

Hi guys,

Example: I have 1 array ArrayTest [10] [10000] and I need move whole 4th row to 2nd line (rewrite data inside array)

My code:

 exist some better way? Main parameter for me is speed operations.

Is possible move whole row inside array? Thank you.

You are actually moving the 5th to the third.
 
Yes. It is only example...
 
endy5: I need move whole 4th row to 2nd line (rewrite data inside array) exist some better way? Main parameter for me is speed operations.
  1. Don't worry about speed, until you can prove that is the bottle neck.
  2. Instead of moving data, just remember that row 2 is available and reuse later. Either a sentinel value, or add an index to the next row (pointers)
 

WHRoeder:

Ok, I want move data becose 1) old row 2 I do not need   2) array will grew (I will insert new actual data therefore I want unnecessary data rewrite)

I would have test larger and larger array..

 
endy5:

Is possible move whole row inside array? Thank you.

Yes.  Use ArrayCopy().

Here is an example:

double ArrayTest[10][5];
ArrayTest[4][0] = 9; ArrayTest[4][1] = 8; ArrayTest[4][2] = 7; ArrayTest[4][3] = 6; ArrayTest[4][4] = 5;
ArrayCopy(ArrayTest, ArrayTest, 10, 20, 5);
Print (ArrayTest[2][3]);

The above code copies the fifth row (remember, arrays are zero-based) to the third row (any data in the third row will be overwritten by the data in the fifth row).

 
You need fifo shift?
 

Thirteen: Thanks

Codersguru: no FIFO princip 

Reason: