Join Slack
Powered by
how can I efficiently copy a Kotlin ByteArray into...
# kotlin-native
z
zt
07/04/2025, 4:01 AM
how can I efficiently copy a Kotlin ByteArray into a pointer to the first byte of an array?
e
ephemient
07/04/2025, 5:57 AM
internal to K/N there is
https://github.com/JetBrains/kotlin/blob/c77930c1ea099c31a28b356371716ec1998d8929/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/NativeMem.kt#L60
but it's not optimized (as the comment right there says)
ephemient
07/04/2025, 6:00 AM
you could try
Copy code
byteArray.usePinned { platform.posix.memcpy(ptr, it.addressOf(0), byteArray.length) }
z
zt
07/04/2025, 11:51 PM
Oh that should work, good idea
2
Views
Open in Slack
Previous
Next