4
Answers

How to write a memcpy method in C#

Barry Carnahan

Barry Carnahan

14y
19.5k
1


Hi all,
I'm trying to expand some cryptographic functionality in the .Net 3.5 framework which, hopefully, will enable CMS functions to run with CNG providers under CAPI. I've reproduced a lot of code using Reflector but one method will not compile, a memory copy using two pointers and a size. It looks like the following:
internal static void memcpy(IntPtr source, IntPtr dest, uint size)
{
   for (uint i = 0; i < size; i++)
   {
      ((long) dest)[i] = Marshal.ReadByte(new IntPtr(((long) source) + i));
   }
}
I've been doing some Googling and some playing around but can't get it right. I know it's not the kind of thing you want to be 'playing around with', that's why I'm going to cross my fingers and hope that someone knows how this code snippet should look in C#.
Answers (4)