java - 确认我在 Java JNA 中正确发送指向 int[] 的指针
问题描述
我正在传递一个指向 int[] 的指针,如下所示,它位于我的 java 结构/类中:
int[] initialDynamicSize = new int[]{1, initialDynamicAllocatedSize};
int[] allFloorsSize = new int[]{1, allFloorsAllocatedSize};
Pointer PTRinitialDynamicSize = new Memory(2*Native.getNativeSize(Integer.TYPE));
PTRinitialDynamicSize.setInt(0*Native.getNativeSize(Integer.TYPE),1);
PTRinitialDynamicSize.setInt(1*Native.getNativeSize(Integer.TYPE),initialDynamicAllocatedSize);
Pointer PTRallFloorsSize = new Memory(2*Native.getNativeSize(Integer.TYPE));
PTRinitialDynamicSize.setInt(0*Native.getNativeSize(Integer.TYPE),1);
PTRallFloorsSize.setInt(1*Native.getNativeSize(Integer.TYPE),allFloorsAllocatedSize);
结构如下所示:
@Structure.FieldOrder({ "str", "size", "allocatedSize", "numDimensions", "canFreeData"})
public class test extends Structure implements Structure.ByReference{
public Pointer str;
//private int numVals;
public Pointer size;
public int allocatedSize;
public int numDimensions;
public boolean canFreeData;
//Static
public test(Pointer str, Pointer size) {
this.str = str;
this.size = size;
}
//Dynamic
public test(Pointer str, Pointer size, int allocatedSize, int numDimensions, boolean canFreeData) {
this.str = str;
this.size = size;
this.allocatedSize = allocatedSize;
this.numDimensions = numDimensions;
this.canFreeData = canFreeData;
}
public test() {
}
}
我从我的 C 代码中收到错误,我想排除此代码的任何错误。接收数据的 C 代码结构是:
struct emxArray_char_T
{
char *data;
int *size; // This is the string array that i am sending
int allocatedSize;
int numDimensions;
bool canFreeData;
};
解决方案
推荐阅读
- c++ - 如何检查该函数是否真的获得了定义为 const 的变量?
- html - 链接悬停动画问题(骑士动画)
- node.js - 是否存在任何与 GitHub API v4 一起使用的 nodejs 库?
- css - 如何使用网格模板区域修复 CSS 网格区域?
- scala - Spark如何在写入时/写入后指定DataFrame的结果文件数
- azure - 如何从 Azure 数据湖分析文件中的 dat 文件中获取列数
- java - 检查 HBase 表中是否存在值
- angular - 注入服务以填充 environment.ts 文件中的值
- selenium - 从 VSTS 托管代理运行 Selenium 测试
- django - {% block something %} 尽管在 if 语句中为 False,但始终显示