Firstly, ditch your
processed
variable, and use
break
instead. This will cause that loop to terminate immediately, instead of running through after you have found what you want.
for (j = 1; j <= 8; j++)
{
for (i = 0; i <= marinePositions.Length / 2 - 1; i++)
{
if (j == marinePositions[i, 0])
{
x++;
output1 = output1 + 8;
break;
}
}
}
This applies to both "j" loops.
Secondly, dump the Garbage Collection stuff - this routine does not create or dispose any data that the GC can handle - it is all local stack based variables.