Pass argument of type void** (pointers of pointers) using Java FFM API
How to pass argument void**
using java FFM API?
Is there a way to get the logical length of a MemorySegment without doing byte arithmetic?
One of the great benefits of the new FFM API in Java 22 is the MemoryLayout
class, which obviates the need for nearly all byte arithmetic. However, there is one remaining place where I can’t seem to avoid it: getting the logical size of an allocated MemorySegment
. As far as I can tell, the only MemorySegment
API returning the amount of memory allocated is the byteSize
operator, which does not take a MemoryLayout
or ValueLayout
instance. So, if I have this code:
Does VarHandle.compareAndSet throw an UnsupportedOperationException when used with longs on 32-bit architectures?
Per the MemoryLayout
Access mode restrictions docs:
What is the difference between `JAVA_LONG` and `JAVA_LONG_UNALIGNED` in `java.lang.foreign.ValueLayout`?
The java.lang.foreign.ValueLayout
API that was introduced in Java 22 provides a convenient method for declaring the layout of manually-managed memory so you don’t need to do byte arithmetic on reads & writes. There are layouts available for all the common primitive types, and many have an _UNALIGNED
variant. To take the example of JAVA_LONG
, here is how it is described: