Title
s

spierce7

05/13/2017, 2:13 AM
Is it possible to pass a Kotlin-native object pointer to C++, and then have C++ pass the pointer back to Kotlin-native? I'm trying to find out if there is any way to pass Kotlin objects between threads without serialization / deserialization.
o

olonho

05/13/2017, 8:20 AM
spierce7: we are working on appropriate API for that, for now an attempt to share object between threads will likely lead to crash. To achieve what you asked for, use StableObjPtr like in https://github.com/JetBrains/kotlin-native/blob/master/samples/libcurl/src/org/konan/libcurl/CUrl.kt#L43, however I would recommend for a reliable solution exchange C structures between threads, not use this API (designed for passing objects as callback data)
🙂 1
s

spierce7

05/13/2017, 4:20 PM
That's essentially what I'm looking to do. Start a thread, pass some initial data to that thread, and then get a response / callback object as a response. Very similar to the current concurrent example. That would still cause a crash?
o

olonho

05/14/2017, 7:07 AM
in some cases - yes, however we’re working on providing proper primitive, so that it will work
s

spierce7

05/14/2017, 8:31 PM
bah. Maybe I'll just wait for that. It's nice to know you can pass Kotlin objects to C++ using StableObjPtr though.