在您发布的代码中,您将其称为:
double * rest = (double *)env->GetDirectBufferAddress(bytebuffer + 12);
这会将12添加到字节缓冲区jobject,而不是数字.
GetDirectBufferAddress()返回一个地址;由于前3个int均为4个字节,因此我相信您正确添加了12个字节,但未将其添加到正确的位置.
您可能打算这样做:
double * rest = (double *)((char *)env->GetDirectBufferAddress(bytebuffer) + 12);
对于您的总体代码,要获得初始的三个整数,而剩下的双精度数,请尝试类似以下操作:
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));
// you said the third int represents the number of doubles following
for (int i = 0; i < doubleCount; i++) {
double d = *rest + i; // or rest[i]
// do something with the d double
}