java - How do I call multiple data types from GetDirectBufferAddress in JNI? -


i bytebuffer via native methods.

the bytebuffer starts 3 ints, contains doubles. third int tells me number of doubles follow.

i able read first 3 ints.

why code crashing when try read doubles?

relevant code first 3 integers:

jniexport void jnicall test(jnienv *env, jobject bytebuffer) {    int * data = (int *)env->getdirectbufferaddress(bytebuffer); } 

relevant code remaining doubles:

double * rest = (double *)env->getdirectbufferaddress(bytebuffer + 12); 

in posted code, calling this:

double * rest = (double *)env->getdirectbufferaddress(bytebuffer + 12); 

this adds 12 bytebuffer jobject, not number.

getdirectbufferaddress() returns address; since first 3 int 4 bytes each, believe correctly adding 12, you not adding in right place.

what meant this:

double * rest = (double *)((char *)env->getdirectbufferaddress(bytebuffer) + 12); 

for overall code, initial 3 ints , remaining doubles, try similar this:

void * address = env->getdirectbufferaddress(bytebuffer); int * firstint = (int *)address; int * secondint = (int *)address + 1; int * doublecount = (int *)address + 2; double * rest = (double *)((char *)address + 3 * sizeof(int));  // said third int represents number of doubles following (int = 0; < doublecount; i++) {     double d = *rest + i; // or rest[i]     // d double } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -