I'm confused on the difference between pinning a K...
# kotlin-native
k
I'm confused on the difference between pinning a Kotlin string and using
getPointer
on a cstr. For context, I need to pass a pointer to String to a C function and have that memory be valid after the current function call pops off the stack. To do that, the cinterop guide mentions allocating the c string in native memory using
Copy code
val cstring = "some string".cstr.getPointer(nativeHeap)
This produces a pointer to valid memory. However, why does this function any differently than
Copy code
val pinnedCstr = "some string".cstr.pin()
I want to manually unpin this value and avoid the copy if I can. This memory is no longer valid once it's accessed from the C library I'm interfacing with and I don't understand why
👀 1