Can someone explain to me why the following structure size is 16 ?
public class StringStruct extends Structure {
public char[] data = new char[4];
public StringStruct() {}
@Override
protected List<String> getFieldOrder() {
return Collections.singletonList("data");
}
}
public class Main {
public static void main(String[] args) {
StringStruct ss = new StringStruct();
// Prints StringStruct: 16
// I was expecting 4...
System.out.println("StringStruct: " + ss.size());
}
}
I want to model structures which own their data
typedef struct {
char data[4];
} StringStruct_s
If I use a byte array instead, it returns the expected value. Still, the char array size is really surprising to me. Is the field interpreted as owning an encoded String ?
So, I launched this executable with various explicit encodings (-Djna.encoding="..."
) to see if it had an effect. No change...