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
Here's how you can keep internal C struct state in a Kotlin class when using JNI:
- Define your C struct in a .h file:
typedef struct MyStruct { int value; } MyStruct;- Create a .c file that implements functions that operate on that struct:
MyStruct* createMyStruct() { MyStruct* s = malloc(sizeof(MyStruct)); s->value = 0; return s; } void deleteMyStruct(MyStruct* s) { free(s); } void setValue(MyStruct* s, int value) { s->value = value; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.