char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding to 64 bytes */
public byte[] _f = new byte[20
- 2 * Native.getNativeSize(NativeLong.class)
- Native.getNativeSize(int.class)]; // Padding to 64 bytes
Unfortunately, on 64-bit systems, sizeof(long) = 8 so the padding calculation equates to zero. This is fine, as Java allows zero-length arrays.
However, when I attempt to use this, I execute the following code to allocate memory for the structure:
Sysinfo info = new Sysinfo();
Pointer p = new Memory(info.size());
This is failing because the Structure's size() method does not allow zero-length arrays.
Exception in thread "main" java.lang.IllegalArgumentException: Invalid Structure field in class Libc$Sysinfo, field name '_f', class [B: Arrays of length zero not allowed: class [B
at com.sun.jna.Structure.calculateSize(Structure.java:848)
at com.sun.jna.Structure.allocateMemory(Structure.java:279)
at com.sun.jna.Structure.ensureAllocated(Structure.java:268)
at com.sun.jna.Structure.size(Structure.java:307)