I want to allocate some memory in C and keep it associated with a java object instance, like this:
void configure(JNIEnv *object, jobject obj, ....) {
char *buf = new char[1024];
// associated <buf> with <obj> somehow
}
And then later free the memory when the java object gets garbage collected - I could do this by calling a JNI function from the finalize() method of the java object.
The question is, how do I associate a C pointer with the java object? Keep a long field in the object and cast the pointer to long? Is there a better way?