Dominaezzz
09/03/2018, 4:35 PMrefTo
function do? Because it seems the target array is unpinned before the function returns.jonnyzzz
09/03/2018, 4:41 PMusingPinned
not usePinned
. And the implementation creates an CValuesRef<>
object that asks for the pointer from the scope.
https://github.com/JetBrains/kotlin-native/blob/master/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/Pinning.kt#L78olonho
09/03/2018, 5:32 PMDominaezzz
09/03/2018, 6:58 PMrefTo
?Dominaezzz
09/03/2018, 6:59 PMrefTo
simply return a value to be pinned in future? Like lazy/on-demand pinning?olonho
09/03/2018, 8:05 PMprivate inline fun <T : Any, P : CPointed> T.usingPinned(
crossinline block: Pinned<T>.() -> CPointer<P>
) = object : CValuesRef<P>() {
override fun getPointer(scope: AutofreeScope): CPointer<P> {
val pinned = this@usingPinned.pin()
scope.defer { pinned.unpin() }
return pinned.block()
}
}
, i.e. object is pinned until the current scope is activeDominaezzz
09/03/2018, 8:13 PMrefTo
but don't "consume" the result, i.e pass to cinterop. It will remain pinned. Until I "consume" it?Dominaezzz
09/03/2018, 8:29 PM