Java JNI - associating resources allocated in C with java objects?

前端 未结 2 1690
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 17:37

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 *bu         


        
2条回答
  •  梦谈多话
    2021-02-04 17:44

    Java doesn't have any concept of native pointer, so storing it as a long is the only real option. But you should not rely on finalize to free the pointer; the finalize method is unreliable as a means of cleaning up resources. See this question for further details.

提交回复
热议问题