internal IntPtr ConvertToMemory() { int size = Marshal.SizeOf(typeof(EncoderParameter)); Debug.Assert(size == (16 + 4 + 4 + 4), "wrong size! (" + size + ")"); IntPtr memory = (IntPtr)((long)Marshal.AllocHGlobal(param.Length * size + Marshal.SizeOf(typeof(Int32)))); if (memory == IntPtr.Zero) { throw SafeNativeMethods.StatusException(SafeNativeMethods.OutOfMemory); } Marshal.WriteInt32(memory, param.Length); for (int i = 0; i < param.Length; i++) { Marshal.StructureToPtr(param[i], (IntPtr)((long)memory + Marshal.SizeOf(typeof(Int32)) + i * size), false); } return(memory); }
public static void WriteInt32(object ptr, int ofs, int val) { WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, int value) => Marshal.WriteInt32(nativeHome, offset, value)); }