Relative Content

Tag Archive for javajava-ffm

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: