[英]JNI - Send a large byte[] buffer to C++
I'm trying to send a large java buffer byte[] (eg 460800) to C++ function using JNI. 我正在尝试使用JNI将较大的Java缓冲区byte [](例如460800)发送到C ++函数。 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 eg2048. 当我打印buf_size时,我得到一些较小的值,例如2048。 It means I'm not receiving full buffer in JNI function.
这意味着我没有在JNI函数中收到完整的缓冲区。 Is there any restriction on the size of buffer that I can send using JNI?
我可以使用JNI发送的缓冲区大小是否有限制? Any idea why it might be happening?
知道为什么会发生吗?
You're casting your array length to a UINT16
. 您正在将数组长度转换为
UINT16
。 Any size larger than 65,535 bytes is going to cause you trouble. 任何大于65,535字节的大小都会给您带来麻烦。
460800 % 65536 is, not surprisingly, 2048. 460800%65536毫无疑问是2048。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.