“base” 是什么意思? JNA 的 Pointer.getPointerArray(long base) 和 Pointer.getStringArray(long base) 中的意思是什么?

发布于 2024-12-04 03:39:03 字数 577 浏览 1 评论 0原文

JNA 中的“基础”是什么意思

Pointer.getPointerArray(long base) 
Pointer.getStringArray(long base)

JNA 指针文档 没有解释什么是“base”这应该是指。

如果它是文本格式化基础,那么为什么它也传递给 getPointerArray?

它可以指内存地址的位数吗?为什么它需要这样的东西传递(如果在java中,它不能自己弄清楚,如果不是我怎么能?)

如果是地址宽度,为什么要使用long?为未来做准备? JNA 项目是否预见到具有 1E19 位宽内存地址总线的大型机器?

它应该是所有位都设置为 1 的 long 吗?

难道是指主机的硬件基础?对于二进制来说,这可能是 2 以外的任何值吗?

它应该是一个偏移量吗?

它可能是数组终止符吗?如果我的终止字符超过 64 位怎么办?如果小于 64 位怎么办?

What does 'base' mean in JNA's

Pointer.getPointerArray(long base) 
Pointer.getStringArray(long base)

?

The JNA Documentation for Pointer doesn't explain what 'base' this is supposed to refer to.

If it is a text-formatting base, then why is it passed to getPointerArray as well?

Could it refer to the number of bits of a memory address? Why would it need such a thing passed (if within java, couldn't it figure that out itself, and if not how could I?)

And if it is the address width, why use long? Preparing for the future? Does the JNA project foresee a massive machine with a memory address bus which is 1E19 bits wide?

Is it supposed to be a long with all bits set to 1?

Could it refer to the hardware base of the host machine? Could this be anything other than 2 for binary?

Is it supposed to be an offset?

Could it be the array termination character? What if my termination character exceeds 64 bits? What if it is less than 64 bits?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-12-11 03:39:03

深入挖掘 JNA 的 Pointer 类源代码,

Pointer.getPointerArray(long base)
Pointer.getStringArray(long base)

...显然是在 基址+地址内存寻址模式在汇编器/硬件级别发现,其中一个寄存器将存储内存地址,而第二个寄存器将存储该地址的偏移量,该偏移量在内存访问。理想情况下,指针将是“基地址”,当您迭代内存内容时,您将调整“偏移”地址。

因此,在这种情况下,基本上“base”意味着“偏移量”:它从指针位置之后的“base”字节开始,然后根据从内存的这些部分读取的地址位置吐出 Pointer/String 对象直到找到空值。我推测使用“base”一词的原因与该方法的内部编码方式有关:

它基于自身创建第二个 Pointer 对象,但将“base”参数作为“偏移量”传递,然后创建一个索引变量称为“offset”...是的。然后它进行迭代,将“偏移量”增加以字节为单位的地址字大小(通常为 8),直到读取到空值。

因此,由于“offset”已经用作局部变量,它会与 offset 参数发生冲突,因此编码器将该方法的偏移参数命名为“base”。

Digging through JNA's source for the Pointer class,

Pointer.getPointerArray(long base)
Pointer.getStringArray(long base)

... apparently refer to 'base' in the context of base+address memory addressing modes found at the assembler/hardware level where one register would store a memory address while a second register would store an offset to that address, which is automatically summed during a memory access. Ideally a pointer would be the 'base address' and as you iterate over the memory's contents you would be adjusting the 'offset' address.

So basically 'base' means 'offset' in this context: It starts at 'base' bytes after the pointer's location and then spits Pointer/String objects based on the address locations it reads from these parts of memory until it finds a null value. I speculate the reason why the word 'base' is used has to do with how the method is coded internally:

It creates a second Pointer object based on itself, but passes your 'base' argument as an 'offset', and then creates an index variable called 'offset'... yeah. Then it iterates, incrementing 'offset' by the address word size in bytes (typically 8) until it reads a null value.

So because 'offset' is already used as a local variable it would clash with the offset parameter so the coder named the method's offset parameter 'base'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文