开发者

What does 'base' mean in JNA's Pointer.getPointerArray(long base) and Pointer.getStringArray(long base)?

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开发者_如何学C 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?


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'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜