Implement explicit and implicit object pinning for interop
This allows passing Kotlin primitive arrays directly to native
This commit is contained in:
committed by
SvyatoslavScherbina
parent
fd35ccbf2e
commit
a6ca64871f
@@ -1,27 +1,19 @@
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
memScoped {
|
||||
val count = 5
|
||||
val values = intArrayOf(14, 12, 9, 13, 8)
|
||||
val count = values.size
|
||||
|
||||
val values = allocArray<IntVar>(count)
|
||||
values[0] = 14
|
||||
values[1] = 12
|
||||
values[2] = 9
|
||||
values[3] = 13
|
||||
values[4] = 8
|
||||
cstdlib.qsort(values.refTo(0), count.toLong(), IntVar.size, staticCFunction { a, b ->
|
||||
val aValue = a!!.reinterpret<IntVar>()[0]
|
||||
val bValue = b!!.reinterpret<IntVar>()[0]
|
||||
|
||||
cstdlib.qsort(values, count.toLong(), IntVar.size, staticCFunction { a, b ->
|
||||
val aValue = a!!.reinterpret<IntVar>()[0]
|
||||
val bValue = b!!.reinterpret<IntVar>()[0]
|
||||
(aValue - bValue)
|
||||
})
|
||||
|
||||
(aValue - bValue)
|
||||
})
|
||||
|
||||
for (i in 0 .. count - 1) {
|
||||
print(values[i])
|
||||
print(" ")
|
||||
}
|
||||
println()
|
||||
for (i in 0..count - 1) {
|
||||
print(values[i])
|
||||
print(" ")
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user