1

I have an IntPtr (c#) given from unmanaged code. I know that this is an reference to an Byte Array with 4096 elements.

Now i want to CONVERT these data from IntPtr to Byte[] WITHOUT Marshal.Copy. Because the memory in kernel space is already allocated. I only want to interprete those data as an byte array.

I know that there a function "InteropUtils.ConvertIntPtrToByteArray-Methode" but it is only available for smart Devices etc.

Maybe somebody had an better idea?

REMberry
  • 172
  • 1
  • 2
  • 12

1 Answers1

0

What you asked is not possible because an IntPtr represents an unmanaged memory region, while a byte[] array represents a managed memory region. It is not possible to treat an unmanaged region as a managed one.

You must either copy the data to a managed region (through Marshal.Copy), or use an unsafe code to manipulate it directly.

Victor Victis
  • 313
  • 1
  • 8