0

I'm trying to pass a char[][] to Rust, which then needs to decode it back to a String.

I've tried a few approaches:

  1. Using Marshal to copy each array with a header of the array length, then reading it back in Rust.

I did this using Marshal.AllocHGlobal, but after the Rust code finished the C# crashes when I try to free the memory. (Same with Marshal.AllocCoTask).

  1. Using GCAlloc to copy the array to unmanaged memory, then loading that

This SEGFAULTed. I don't know why, but I couldn't find enough documentation over GCAlloc to figure it out

  1. Just passing the array to Rust

Between https://github.com/rust-lang/rust/issues/58905 and https://medium.com/jim-fleming/complex-types-with-rust-s-ffi-315d14619479, this route seemed ill-advised.

So what can I do to pass this dang array? The first approach works fine with a char[], and I've got no clue why it crashes (the memory pointers are actual pointers, not 0 also).

Mohammad Aghazadeh
  • 2,108
  • 3
  • 9
  • 20
Big_Bad_E
  • 947
  • 1
  • 12
  • 23

0 Answers0