问题
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