Is it possible to use the new System.Memory Span struct with two dimensional arrays of data?
double[,] testMulti =
{
{ 1, 2, 3, 4 },
{ 5
You can create a Span with unmanaged memory. This will allow you to Slice and Dice indiscriminately.
unsafe
{
Span something = new Span(pointerToarray, someLength);
}
Full Demo
unsafe public static void Main(string[] args)
{
double[,] doubles = {
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 9.5f, 10, 11 },
{ 12, 13, 14.3f, 15 }
};
var length = doubles.GetLength(0) * doubles.GetLength(1);
fixed (double* p = doubles)
{
var span = new Span(p, length);
var slice = span.Slice(6, 5);
foreach (var item in slice)
Console.WriteLine(item);
}
}
Output
7
8
9
9.5
10
Other options would be to reallocate to a single dimension array, cop the penalty and do not Pass-Go
BlockCopymemcpy directly and use unsafe and pointersCast eg multiDimensionalArrayData.Cast().ToArray() The first 2 will be more performant for large arrays.