Confirmation I am sending the pointer to int[] correctly in Java JNA

老子叫甜甜 提交于 2020-05-17 06:06:23

问题


I am passing a pointer to an int[] as here, which is in my structure/class in java see below:

        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);

The structure looks like this:

@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() {
    }
}

I am getting errors back from my C code, i want to rule out any errors with this code. the C code struct that receives the data is:

struct emxArray_char_T
{
  char *data;
  int *size; // This is the string array that i am sending
  int allocatedSize;
  int numDimensions;
  bool canFreeData;
};

This is a MatLab Struct https://uk.mathworks.com/help/coder/ug/use-c-arrays-in-the-generated-function-interfaces.html#mw_0cae9a4a-b74d-43f9-aae0-ed192db73d22

来源:https://stackoverflow.com/questions/61821053/confirmation-i-am-sending-the-pointer-to-int-correctly-in-java-jna

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!