[code-reflection] RFR: Use memory segment
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Feb 26 10:18:20 UTC 2025
On Tue, 25 Feb 2025 19:09:36 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
> Replace many uses of `ByteBuffer` use with idiomatic `MemorySegment` use. This also tends to make clearer the life cycle of segments. Generally in any ONNX APIs we design i think we should avoid exposing `*Buffer`. The "escape hatch" for accessing the data of a `Tensor` should be `MemorySegment`.
cr-examples/onnx/src/main/java/oracle/code/onnx/OnnxProtoBuilder.java line 320:
> 318: .buf.toByteArray();
> 319: // OnnxProtoPrinter.printModel(ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN));
> 320: return Arena.ofAuto().allocate(bytes.length).copyFrom(MemorySegment.ofArray(bytes)).asReadOnly();
I suggest using `allocateFrom(JAVA_BYTE, bytes)` to avoid the zeroing
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/328#discussion_r1971316325
More information about the babylon-dev
mailing list