Reputation: 2357
I'm trying to send a large java buffer byte[] (e.g. 460800) to C++ function using JNI. Below is the sample code:
JNIExport void JNICALL XXXXXX_onRecvData(JNIEnv *env, jclass class, jbyteArray data) {
jbyte *pData = NULL;
pData = env->GetByteArrayElements(data, NULL);
// call some function here
Method((UINT8 *) pData, (UINT16)(env->GetArrayLength(data));
env->ReleaseByteArrayElements(data, pData, 0);
}
Where
Method(uint8_t* buf, uint32_t buf_size) {
// print buf_size
}
When I print buf_size, I get some small value e.g.2048. It means I'm not receiving full buffer in JNI function. Is there any restriction on the size of buffer that I can send using JNI? Any idea why it might be happening?
Upvotes: 0
Views: 901
Reputation: 39013
You're casting your array length to a UINT16
. Any size larger than 65,535 bytes is going to cause you trouble.
460800 % 65536 is, not surprisingly, 2048.
Upvotes: 2