I have a 3D data array which represents a stack of 2D data. In this particular case, the stack only contains one element. What is the fastest way to map this data to a linear array?
I was planning to take the following approach:
public static int[] ToBuffer<(this int[, ,] buffer3D, int w, int h)
{
int[] buffer = new int[w * h * 1];
for (int i = 0; i < (w * h); i++)
{
buffer[i] = buffer3D[(int)Math.Floor(i / (double)w), i % w, 0];
}
return buffer;
}
But it occurred to me that there might be some way to take advantage of how the data is already stored in memory. Is there some other mapping approach that should be employed in csharp?