3 ms·
I’m not sure I understand you, but you can do ``` var segment = MemorySegment.ofAddress(somePointer, sizeofStruct, memorySession); segment.set(ValueLayout.JAVA
by kaba0 4y ago
I’m not sure I understand you, but you can do
```
var segment = MemorySegment.ofAddress(somePointer, sizeofStruct, memorySession);
segment.set(ValueLayout.JAVA_LONG, offset, value)
```
- renewiltord 4y agoIs it possible to lay out some struct-like thing into that memory segment and just read the whole thing for convenience? Appreciate the example. Thank you.
- kaba0 4y agoYes, for FFI jextract can also auto-generate helper classes, so some C struct named tb_cell with a field named ch typed int, you could access its fields like tb_cell.ch$get(memorySegment) and tb_cell.ch$set(memorySegment, value). Of course you are not required to do FFI, you may want to use this API to speed up some very memory-sensitive operation. Then you can define your own memory layout, specifying precisely endianness, alignment, padding, anything, and access it comfortably through these APIs.
- renewiltord 4y agoWell, wow, I'm going to take a look at this. Much appreciated. Do you happen to know if the `get` causes allocation in the Java side there?