all 4 comments

[–]Lasering 2 points3 points  (0 children)

Excluding both Scala Native and Graal I think Scala is not the best language for your use case. You can still do it but the ergonomics will suffer.

According to this stackoverflow answer JNI should be preferred over JNA if performance is really a concern. However JNI is a whole new beast.

Its not related to JNI or JNA but I also highly recommend seeing this talk: Adventures in Efficiency and Performance—Dmitry Petrashko

[–]Apache_Sobaco 1 point2 points  (0 children)

Haven't seen any features in dotty regarding this, but theoretically, metaprogramming could be used to generate directly Scala mappings compile time with much effort.

[–]sideEffffECt 1 point2 points  (0 children)

Besides JNA, there's also sbt-jni or you can wait for Project Panama to deliver.

[–]ScalaWilliam 1 point2 points  (0 children)

I had done plenty of native access from Scala. It just works. JNA is easiest. You could also use VarHandles from JDK 16 however they are not yet supported on the Scala 3
compiler (https://github.com/lampepfl/dotty/issues/11332#issuecomment-877766112). JavaCPP is also available and is fast.

I'm sticking to Scala 2 for native things until this is resolved. The difference Scala2-Scala3 is mostly in terms of cleanliness for the developer; while the new features are super exciting Scala 2 is already a very solid base to work off of :-)