I have requirement to convert double array to IntPtr and this IntPtr to byte array.
I want to do the reversal also just confirm values stored in byte array is of correct int array.
double[] dmanagedArray = new double[length];
for (int intI = 0; intI < dmanagedArray.Length; intI++)
{
dmanagedArray[intI] = intI * 10;
}
int size = Marshal.SizeOf(dmanagedArray[0]) * dmanagedArray.Length;
IntPtr srcPtr1 = Marshal.AllocHGlobal(size);
// This will copy double array to IntPtr.
Marshal.Copy(dmanagedArray, 0, srcPtr1, dmanagedArray.Length);
// Now let's convert this IntPtr to byte array
byte[] byteArray = new byte[dmanagedArray.Length]
//Marshal.Copy(srcPtr1, byteArray, 0, byteArray.Length);
In my case what is happening is , byte[] now contains all the values as 0.
which I think is wrong. How to do right conversion.