I need to pass a `ByteArray` buffer from Kotlin to...
# kotlin-native
k
I need to pass a
ByteArray
buffer from Kotlin to C so that it can be written to. The underlying lib expects it in the form of an
iovec
. Do I have to use
StableRef
to do this?
iovec.iov_base
is expecting the buffer in the form of a
COpaquePointer
.
n
You can look into
ByteArray.refTo()
, or pin and then
addressOf()
. The first is simpler but it will unpin after the C function returns, which might not be desirable.
k
What's the difference between using stableref and pinning? They seem really similar
Seems like stableref is maybe a two way street versus pinning being one way?
n
Yeah, they have different APIs and features as you noticed, but it's the same concept under the hood. I always thought they should be one thing