问题描述
我有一个本地方法,可以对位图进行一些工作.在方法内部,我通过一个方法调用来获取图像数据,该方法将数据写入使用NewIntArray
创建的jintArray
参数:
I have a native method that does some work on a bitmap. Inside the method I grab the image data via a method call that writes the data to a jintArray
parameter that I've created with NewIntArray
:
jintArray pixels = env->NewIntArray(width * height);
我不需要将此数组返回给正在调用的Java代码-仅用于在此方法中进行处理.我需要在pixels
上致电ReleaseIntArrayElements
吗?如果是这样,由于不需要将其复制回Java数组,该为elems
参数传递什么内容?
I don't need to return this array back to the calling Java code - it's only for processing while in this method. Do I need to call ReleaseIntArrayElements
on pixels
? If so, what do I pass for the elems
parameter, since I don't need to copy it back to a Java array?
void (JNICALL *ReleaseIntArrayElements) (JNIEnv *env, jintArray array, jint *elems, jint mode);
void (JNICALL *ReleaseIntArrayElements) (JNIEnv *env, jintArray array, jint *elems, jint mode);
推荐答案
您无需对其进行任何操作.它是一个本地引用,当您的JNI方法退出时,它将被清除.正如爱德华·汤普森(Edward Thompson)所暗示的那样,ReleaseIntArrayElements()
与GetIntArrayElements().
相反,它没有其他功能.
You don't need to do anything with it. It is a local reference and it will be cleaned up when your JNI method exits. As Edward Thompson hints above, ReleaseIntArrayElements()
is the converse of GetIntArrayElements().
It has no other function.
这篇关于我需要在使用NewIntArray创建的数组上调用ReleaseIntArrayElements吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!