I'm trying to do a little "memcpy" hack in C#. I keep getting stuck on this part, because it won't convert System.Type to byte*
public unsafe void memcpy(byte* dest, object src, int length)
{
byte* nsrc;
byte* ndst;
nsrc = (byte*)((src.GetType())src);
}
As you see I try to get the type of the object, and then cast it to the original object.
Any ideas?
Update:
Maybe using serialization?
private byte[] ObjectToByteArray(Object obj)
{
if(obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
private void memcpy(byte[] dest, int pos, object src, int len)
{
byte[] ba = ObjectToByteArray(src);
Array.Copy(ObjectToByteArray(src), 0, dest, pos, len);
}