creating an intarray in JNI

M

marydeepthy

Hi,

I have a JNI call, which should return an int array.

have created an intarray of size 3

jintArray cod = (*env)->NewIntArray(env,3);\

now i want to set the elements of the array. i have the function

(*env)->SetIntArrayRegion(env, cod, 0, 3, (jint *)nativeArray);

my problem is, to use this function i have to make a native array.
but all i have is the members of this native array, which are pointers
to unsigned integers.can i assign these members directly, without
creating the nativeArray? Please do help me.

Regards

Mary Deepthy
 
M

marydeepthy

i have PUNIT8 dev1;
PUNIT8 dev2;
PUNIT8 dev3;
can i give

(*env)->SetIntArrayRegion(env, cod, 0, 1, (jint *)dev1);
(*env)->SetIntArrayRegion(env, cod, 1, 1, (jint *)dev2);
(*env)->SetIntArrayRegion(env, cod, 2, 1, (jint *)dev3);

like this???
 
M

marydeepthy

i have PUINT8 dev1;
PUINT8 dev2;
PUINT8 dev3; where PUINT8 is pointer to unsigned short int.
can i give


(*env)->SetIntArrayRegion(env, cod, 0, 1, (jint *)dev1);
(*env)->SetIntArrayRegion(env, cod, 1, 1, (jint *)dev2);
(*env)->SetIntArrayRegion(env, cod, 2, 1, (jint *)dev3);


like this???
 
R

Roedy Green

SetIntArrayRegion

Setting them all in one shot will a be a lot faster than setting them
one at a time. This requires getting your ducks in a row with a native
array.

If you really want to do them one at a time, create a JAVA method to
set elements one at a time that takes a value and index parameter
 
G

Gordon Beaton

I have a JNI call, which should return an int array.

have created an intarray of size 3

jintArray cod = (*env)->NewIntArray(env,3);\

now i want to set the elements of the array. i have the function

(*env)->SetIntArrayRegion(env, cod, 0, 3, (jint *)nativeArray);

my problem is, to use this function i have to make a native array.
but all i have is the members of this native array, which are pointers
to unsigned integers.can i assign these members directly, without
creating the nativeArray? Please do help me.

Get a pointer to the array elements, make any necessary changes, then
propagate those changes back to the original array:

jint *elems = (*env)->GetIntArrayElememts(env,cod,NULL);

elems[0] = 1;
elems[1] = foo(10);
elems[2] = 42;

(*env)->ReleaseIntArrayElements(env,cod,elems,0);

(untested code)

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top