How do I keep internal C struct state in my Kotlin class when using JNI?
- User
How do I keep internal C struct state in my Kotlin class when using JNI?
Assistant
When using JNI to access C structs, accessing the internal state of the struct can be a bit tricky. One way to do this is to create a Kotlin object that wraps the C struct and keep all the state information in that Kotlin object. Here is an example:
val cStruct = CStruct.newInstance() val kotlinObject = KotlinObject(cStruct) val internalState = kotlinObject.internalStateIn this example,
CStructis a struct that has internal state information that needs to be accessed from Kotlin.KotlinObjectis a Kotlin class that wraps the C struct and has an internal state objectinternalStatethat stores the internal state information.kotlinObjectis an instance of the Kotlin class and can be used to access the internal state information.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.