So I want to copy the contents of a 2D array to another array of the exact same type. Here is how the array is created:
GridUnit** newGrid;
newGrid = new GridUnit*[width];
for (int i = 0; i < width; i++)
newGrid[i] = new GridUnit[height];
GridUnit is size 16 (4 floats). So that's all initialised fine, no problems with using it as it is after I have ran the for loops to actually fill the values with some data. Now what I want to do is copy the contents of another array into this one (without for loops if possible). This is what I have been trying to do so far:
memcpy(&newGrid, &grid, height * width * 16);
'grid' is identical to 'newGrid' in terms of its size and type. However, this does not work. I know the memcpy is possibly not correct, but having tried multiple different setups using this, I don't know what's going wrong with it anymore, so any help would be welcome!
See Question&Answers more detail:os