Release<PrimitiveType>ArrayElements Routines - ReleaseFloatArrayElements
void Release<PrimitiveType>ArrayElements(JNIEnv *env,ArrayType array, NativeType *elems, jint mode);
A family of functions that informs the VM that the native code no longer needs access to
elems. The elems argument is a pointer derived from array using the corresponding Get<PrimitiveType>ArrayElements() function. If necessary, this function copies back all changes made to elems to the original array. (ReleaseFloatArrayElements)
The
mode argument provides information on how the array buffer should be released. mode has no effect if elems is not a copy of the elements in array. Otherwise, mode has the following impact, as shown in the following table:
Table 4-10 Primitive Array Release Modes (ReleaseFloatArrayElements)
mode
|
actions
|
|---|---|
0 |
copy back the content and free the
elems buffer |
JNI_COMMIT |
copy back the content but do not free the
elems buffer |
JNI_ABORT |
free the buffer without copying back the possible changes
|
In most cases, programmers pass “0” to the
mode argument to ensure consistent behavior for both pinned and copied arrays. The other options give the programmer more control over memory management and should be used with extreme care. (ReleaseFloatArrayElements)
The next table describes the specific routines that comprise the family of primitive array disposers. You should make the following substitutions:
- Replace Release<PrimitiveType>ArrayElements with one of the actual primitive array disposer routine names from Table 4-11.
- Replace ArrayType with the corresponding array type.
- Replace NativeType with the corresponding native type for that routine.
Table 4-11a Release<PrimitiveType>ArrayElements Family of Array Routines
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-11b Release<PrimitiveType>ArrayElements Family of Array Routines
PARAMETERS of ReleaseFloatArrayElements
env: the JNI interface pointer.array: a Java array object.elems: a pointer to array elements.mode: the release mode.
Example of ReleaseFloatArrayElements
JNIEXPORT void JNICALL Java_com_android_Coordinates_Updates
(
JNIEnv * env,
jobject obj,
jobjectArray coordinates
)
{
int size = env->GetArrayLength(coordinates);
for(int i = 0; i < size; i ++)
{
jfloatArray row = (jfloatArray)env->GetObjectArrayElement(coordinates, i);
jfloat *elements = env->GetFloatArrayElements(row , 0);
env->ReleaseFloatArrayElements( row , (jfloat *)elements, 0);
env->DeleteLocalRef(row); }
}