4

How can I convert cArrayPointer to a simple Array/List when using c-interop?

val myArray: Array<Int> = memScoped {
    val cArray = allocArray<IntVar>(5)
    fill(cArray)
    cArray.toSimpleArray()     <--- There is no such function
}
Feedforward
  • 4,521
  • 4
  • 22
  • 34

1 Answers1

1

I'd recommend to make it somehow like this:

val myArray: Array<Int> = memScoped {
        val length = 5      //cause I don't know how to get C-array size
        val cArray = allocArray<IntVar>(length)
        (0 until length).map { cArray[it] }.toTypedArray()
}

As one can see in the documentation, CArrayPointer is nothing but a typealias of CPointer. So, I suppose there can't be anadditional functionality, like one you desire.

Artyom Degtyarev
  • 2,704
  • 8
  • 23