Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
It does allow for unsafe pointer math, I have some examples here where I've ported io_uring to use native Java Foreign Memory API with no external headers/bindings:
https://github.com/GavinRay97/panama-liburing/blob/6a80673e7...
Going to copy my Reddit comment over to HN because I think it's valuable:
---
One of the coolest things that's been worked on (by this same author, no less!) isn't even in the article!
Per has written a pretty-printer for MemorySegments and ByteBuffers that can hex-dump memory or render memory/buffers as their "struct" representations given some MemoryLayout.
You can also customize it with your own printers, it's wicked cool and helps so much to debug buffers when working with them.
https://github.com/openjdk/panama-foreign/pull/695
What do I mean by that? Have a look at this comment for an image of a raw memory structure layout I represented with MemoryLayout, and the pretty-print rendering of it:
https://github.com/openjdk/panama-foreign/pull/695#issuecomm...
This is one level below P/Invoke. It just offers a linking runtime API.
There's also has a tool that can generate all the bindings from a C header file automatically: https://github.com/openjdk/jextract
Then it doesn't really matter whether annotations are used or not, or some more low-level linker API (like FFM went with). As a user you just call into the generated bindings.
That's the philosophy: the JDK provides the low-level capabilities, and jextract provides the 'civilization', i.e. a usability focused layer on top. One of the advantages is that the JDK doesn't compete with other existing solutions, and those existing solution can benefit from the new linking runtime APIs as well.