Fast 1D to 2D Array Copy
Can anyone suggest a fast method for copying a 1d array to a 2d array, I'm currently doing the following but seems slow and would like to speed it up some? Is it possible to use memcpy to do this same thing?
buffer_p = malloc(MAX_CAPTURE_LENGTH);
x = 0;
for (j = 0; j < captureLength16; j+=2)
data_matrix[x] = *(buffer_p+j);
data_matrix[x] = *(buffer_p+j+1);
In the memory, an 1d array is same as a 2d array.
Correct me if I'm wrong...but you can use 2d indices wrt to any array.. Wouldn't that eliminate the need for copying?
In this case, memcpy isn't going to be good for you, since you are changing the order of things. If you get your 2D array switched so that the x was first and the 0/1 was second, then you'd be somewhere.
Why are you using malloc in C++?
Why do you need to copy?