On Fri, 13 May 2022 12:33:10 GMT, Maurizio Cimadamore <mcimadam...@openjdk.org> wrote:
> This patch makes MemorySegment::ofBuffer more general, by allowing clients to > pass *any* `Buffer` instance, not just `ByteBuffer`. > This allows us to match expressiveness of JNI API, where JNI clients can > obtain the address of any direct buffer instance, using the > `GetDirectBufferAddress` function. > > We thought about also providing a more general way to view a segment as a > buffer (e.g. asIntBuffer) but doing that doesn't seem worth it: direct > buffers can only created form `ByteBuffer`. > So, to create a direct `IntBuffer`, clients have to first create a direct > `ByteBuffer` then to view that buffer as an `IntBuffer`. > > In other words, `IntBuffer` and friends are not first-class citizens in the > `Buffer` API. As such it would not be possible to map many memory segments > into an `IntBuffer`; in fact, the only segment we could safely map into an > `IntBuffer` would be an _heap_ segment backed by an `int[]`. As such it > doesn't seem worth adding a lot of API surface (in terms of additional > overloads) for such a corner case. This pull request has now been integrated. Changeset: 89a1d055 Author: Maurizio Cimadamore <mcimadam...@openjdk.org> URL: https://git.openjdk.java.net/jdk/commit/89a1d055d93ad57bcec7c1accb3f53b4c30f594d Stats: 95 lines in 8 files changed: 55 ins; 1 del; 39 mod 8286715: Generalize MemorySegment::ofBuffer Reviewed-by: jvernee ------------- PR: https://git.openjdk.java.net/jdk/pull/8701