How to assign more than one array into a pointer in a fixed statement

  • Thread starter Thread starter Silvers11
  • Start date Start date
S

Silvers11

Guest
Hello

I have a question about a code that I use. If we look at the line:

fixed (byte* fixedInput = &array2D[5, 0])

Here I assign the 5th index in the array2D to the pointer fixedInput.

Complete code:

public unsafe static void testFunction()
{
//Create dummy values
byte[,] array2D = new byte[16, 1000]; byte num = 0;
for (int i = 0; i < 16; i++)
{
for (int i2 = 0; i2 < 1000; i2++)
{
array2D[i, i2] = num;
num++; if (num > 3) { num = 0; }
}
}

/*----------------------------------------------------------------------------------------*/
unsafe
{
//Below starts the SIMD calculations!
fixed (byte* fixedInput = &array2D[5, 0]) //index 5 with start at 0!
{


}
}
}


The problem that I have now, is that I would need to be able to assign up to 16 indexes from the array2D into fixedInput somehow. But I am not sure how to do this.

I will give a code example to show what I mean(but the code below is ofcourse wrong but perheps gives an idéa of what I am trying to achieve:

1. Somehow I would need an array for the fixedInputs?

2. Then somehow, how it would be possible to assign array2D[0, 0] into fixedInputs[0] and array2D[1, 0] into fixedInputs[1] but here I would need a dynamic solution as I could assign up to 16 different indexes from array2D (0-15)

byte*[] fixedInputs = new byte*[2];

//The below needs to have a dynamic solution as I could have
//up to 16 different "fixedInputs[0-15]. How do do that also?
fixed (fixedInputs[0] = &array2D[0, 0] && //Assign 0,0 to fixedInputs[0]
fixedInputs[1] = &array2D[1, 0]) //Assign 1,0 to fixedInputs[1]


Thank you

Continue reading...
 
Back
Top