Get<PrimitiveType>ArrayElements Routines - GetFloatArrayElements
NativeType
*
Get<PrimitiveType>ArrayElements(JNIEnv *env,
ArrayType
array, jboolean *isCopy);
A family of functions that returns the body of the primitive array. The result is valid until the correspondingRelease
<
PrimitiveType>
ArrayElements() function is called. Since the returned array may be a copy of the Java array, changes made to the returned array will not necessarily be reflected in the original array
until Release<PrimitiveType>ArrayElements()
is called. (GetFloatArrayElements)
If
isCopy
is not NULL
, then *isCopy
is set to JNI_TRUE
if a copy is made; or it is set to JNI_FALSE
if no copy is made.
The following table describes the specific primitive array element accessors. You should make the following substitutions: (GetFloatArrayElements)
- Replace Get<PrimitiveType>ArrayElements with one of the actual primitive element accessor routine names from the table.
- Replace ArrayType with the corresponding array type.
- Replace NativeType with the corresponding native type for that routine.
Regardless of how boolean arrays are represented in the Java VM,
GetBooleanArrayElements()
always returns a pointer tojbooleans
, with each byte denoting an element (the unpacked representation). All arrays of other types are guaranteed to be contiguous in memory.
Table 4-9a Get<PrimitiveType>ArrayElements Family of Accessor Routines
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-9b Get<PrimitiveType>ArrayElements Family of Accessor Routines
PARAMETERS of GetFloatArrayElements
env
: the JNI interface pointer.array
: a Java string object.isCopy
: a pointer to a boolean.RETURNS of GetFloatArrayElements
Returns a pointer to the array elements, or
NULL
if the operation fails.
Example of GetFloatArrayElements
JNIEXPORT jfloatArray JNICALL Java_jnimath_act_JnimathActivity_test
(JNIEnv *env, jobject obj, jfloatArray fltarray1, jfloatArray fltarray2)
{
jfloatArray result;
result = env->NewFloatArray(3);
if (result == NULL) {
return NULL; /* out of memory error thrown */
}
jfloat array1[3];
jfloat* flt1 = env->GetFloatArrayElements( fltarray1,0);
jfloat* flt2 = env->GetFloatArrayElements( fltarray2,0);
vecLoad(flt1[0], flt1[1], flt1[2], flt2[0], flt2[1], flt2[2]);
vecAdd(vec, vec2);
array1[0] = vecRtrn[0];
array1[1] = vecRtrn[1];
array1[2] = vecRtrn[2];
env->ReleaseFloatArrayElements(fltarray1, flt1, 0);
env->ReleaseFloatArrayElements(fltarray2, flt2, 0);
env->SetFloatArrayRegion(result, 0, 3, array1);
return result;
}