MemorySegment.ofAddress(...).reinterpret(...)

Brian S O'Neill bronee at gmail.com
Wed Jul 5 22:19:26 UTC 2023


I'm converting one of my projects from Unsafe to java.lang.foreign, and 
one thing that I find annoying is the two step process for defining a 
MemorySegment which refers to an arbitrary address. I call reinterpret 
every single time, which is both tedious and error prone. I've forgotten 
to do this a few times, and the resulting exception is quite confusing 
at first.

It would be nice of the ofAddress method was overloaded to accept a 
length. Code that uses it becomes smaller, and it skips the extra object 
allocation which may or may not be eliminated by escape analysis.


More information about the panama-dev mailing list