https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
a

Adam Cooper

08/31/2022, 4:29 AM
I'm also wondering: I've had an easy time using `ByteArray`s for C functions which want to accept a
char **
to write to, but what would be the best way to pass, say, an
int *
or any other primitive pointer? I can use
alloc
within
memScoped
, but is there any way to use a variable on the stack rather than the heap?
n

napperley

08/31/2022, 9:58 PM
For the CPointer stuff the heap has to be used.
The stack in Kotlin Native programs/libraries can only be used on the Kotlin side.
Kotlin has very limited stack support, although there are Value classes ( https://kotlinlang.org/docs/inline-classes.html ) which is currently in development. It is unknown if a Value class can be passed through as a C struct to a C function (by value or reference/pointer). Having such a feature would be very useful (makes things easier/convenient), and would cover some use cases.
a

Adam Cooper

08/31/2022, 10:14 PM
Thanks! This is helpful to know. Hopefully we get the chance to have more control over memory for C interop in the future.
2 Views