问题描述
我记得有每浮动4个字节。
我可以用GetByteArrayElements字节数组传递从Java到C ++。
但由于4个字节等于浮动,我可以用GetByteArrayElements在Java字节来传递和处理呢?
I remembered that there were 4 Bytes per float.And I can use GetByteArrayElements to pass a byte array from Java to C++.But Since 4 Bytes is equal to a float, can I use GetByteArrayElements to pass in a Java byte and manipulate it?
由于只有GetByteArrayElements和GetPrimitiveArrayCritical将返回数据的实际指针和推动速度。
Since only GetByteArrayElements and GetPrimitiveArrayCritical would return a actual pointer of data and push speed.
推荐答案
您不能使用 GetByteArrayElements()
访问浮动[]
。您可以使用 GetPrimitiveArrayCritical()
其限制范围内,这将是一样快,因为它可以。
You cannot use GetByteArrayElements()
to access float[]
. You can use GetPrimitiveArrayCritical()
within its limitations, and this will be as fast as it could be.
但你的假设是错误的: GetFloatArrayElements()
不一定会复制的元素。如果不复制,它会给你的实际指向Java数组,如果你需要逐字节访问这个数组在C ++ code,可以reinter preT为无符号字符*
。
But your assumption is wrong: GetFloatArrayElements()
will not necessarily copy the elements. If it does not copy, it will give you the actual pointer to the Java array, and if you need byte-by-byte access to this array in your C++ code, you can reinterpret it as unsigned char *
.
这篇关于NDK:传递Jfloat阵列从Java到C ++通过GetByteArrayElements?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!