I'm trying to pass a Scala array to native code and need to do the conversion. How to convert Array[Byte] to Ptr[Byte] in Scala Native?
Scala Native - Convert Array[Byte] to Ptr[Byte]
80 views Asked by R A At
2
There are 2 answers
0
On
This is now built-in (since Scala Native 0.4.8):
import scala.scalanative.unsafe.*
val arr: scala.Array[Byte] = new Array[Byte](1024)
val ptr: Ptr[Byte] = arr.at(0)
No Zone required, but I would assume the array won't be copied, so the pointer will only be valid as long as the array doesn't get GCed.
My best solution so far is this: