How to copy a 1D array to 3D array efficiently in C#? -
I have a linear array that I need to resize as a pile of 2D data. In the case, the stack contains only one element so that there is an array with the output dimension (height, width, 1).
This is related to one, where I was asking about the same operation from the other direction (1D to 1D).
What is the fastest way to map this data into a 3D array?
I was planning to take it (byte [] buffer, int w, int h) {byte [,] buff 3d = new byte [h, w, 1] ; For (int i = 0; i But it seems possible to take advantage of how data is already stored in the memory to copy more than one element at a time. Is there some other mapping approach that can be employed in C #? It is likely to be somewhat faster: public stable byte [,] ToBuffer3Da (this byte [ ] Buffer, int w, int h) {byte [,,] buff3d = new byte [h, w, 1]; Buffer BlockCopy (buffer, 0, buff 3d, 0, h * w); Return Buff 3D; }
Comments
Post a Comment