Hi! How can i use `allocArrayOf()` inside `memScop...
# kotlin-native
a
Hi! How can i use
allocArrayOf()
inside
memScoped{ }
to alloc array of
double
? I’m surprised that it works only for
float
. Kotlin version
1.3.30
d
Copy code
memScoped {
    val array = cValuesOf(0.0, 1.0).ptr
}
Is the next best thing I guess.
a
Yes, it works. Thank you! Also something like this can work:
Copy code
fun MemScope.allocDoubleArrayOf(vararg elements: Double): CArrayPointer<DoubleVar> {
    val cArrayPointer = allocArray<DoubleVar>(elements.size)
    elements.forEachIndexed { index, value ->
        cArrayPointer[index] = value
    }
    return cArrayPointer
}
d
You might as well just pin the array.
Take a look at
usePinned
.