Is there any way to set global memory byte alignment for all data structures in JNA library (*.dll Java wrapper)?
Sometimes I have to determine correct alignment by trial and error during implementation and currently I'm doing this in very clumsy way - I'm setting data alignment (super(ALIGN_NONE)) in each and every structure (a lot of structures in separate files).
edit: The best way to solve my problem was to extend Structure:
public abstract class StructureAligned extends Structure {
public static final int STRUCTURE_ALIGNMENT = ALIGN_NONE;
protected StructureAligned() {
super(STRUCTURE_ALIGNMENT);
}
protected StructureAligned(Pointer p) {
super(p, STRUCTURE_ALIGNMENT);
}
}
..but this led to next question: Which (Pointer) constructor is better and why:
super(p, STRUCTURE_ALIGNMENT);
or
super(STRUCTURE_ALIGNMENT);
read();
or
super(STRUCTURE_ALIGNMENT);
useMemory(p);
read();
?