0

Now I'm Converting c++ code to c#, and I have some problems related to memcpy, unsigned char*

below is my c++ code

cBin and aBin both are 2D Char array, and others are all integer type

would you guys convert above c++ code to c#?

Thank you

memcpy ( (unsigned char *) cBin + (nYpos + height) * COL_MAX + BIN_RECT.left + width, (unsigned char *) aBin + nYpos * COL_MAX + BIN_RECT.left, nColCnt )
Loocid
  • 6,112
  • 1
  • 24
  • 42
황성환
  • 21
  • 1

2 Answers2

0

Off the top of my head, I would suggest Array.Copy (https://learn.microsoft.com/en-us/dotnet/api/system.array.copy?redirectedfrom=MSDN&view=netframework-4.8#overloads)

Array.Copy(cBin, (nYpos + height) * COL_MAX + BIN_RECT.left + width, aBin, nYpos * COL_MAX + BIN_RECT.left, nColCnt)

(Untested, and assuming the other variables are still available under the same names)

Edit: Note that Array.Copy index and size parameters are in units of the array member, while memcpy is in bytes. You may need to divide by the size of whatever is in the arrays.

memtha
  • 797
  • 5
  • 24
0

Since you have an array from strings I would suggest to use Array.Copy

public static void Copy (Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length);
cKai
  • 57
  • 10