jna 构造函数_如何为JNA库中的所有结构设置全局内存字节对齐?

在JNA库中,如何为所有结构设置全局内存字节对齐?目前的做法是在每个结构(分别在不同文件中)中设置数据对齐(super(ALIGN_NONE))。最佳解决方案是创建一个抽象的Structure子类,如StructureAligned,并指定所需的对齐类型。对于构造函数的选择,可以使用super(p, STRUCTURE_ALIGNMENT)或super(STRUCTURE_ALIGNMENT)结合read()或useMemory(p);read(),具体取决于需求。如果JNA未正确计算平台上的默认对齐方式,应报告为JNA的bug;若库内部使用了任意对齐,那么通过公共基类关闭所有结构的对齐更为合适。" 79301833,7456199,理解Android广播机制与应用场景,"['Android开发', '广播机制', '进程通信', '事件模型']
摘要由CSDN通过智能技术生成

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:<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值