Skip to content

A Scala library for type-safe direct memory access via Foreign Functions & Memory API

License

Notifications You must be signed in to change notification settings

YandexClassifieds/alien-memory

Repository files navigation

alien

Alien is a library for type safe direct memory access using structures introduced in JDK 22 Foreign Function & Memory API.

Region.fresh.shared { implicit region =>
  val layout = ("a" := Values.Long) >>:
               ("seq" := Values.Long * 123) >>:
               ("b" := Values.Char)
  val ptr = layout / "seq" / % / $
  val memory = Memory.allocate(layout)
  ptr.set(memory, 0, 42)
}

Getting started

Add alien as a dependency to your build.sbt:

libraryDependencies += "com.yandex.classifieds" %% "alien-memory" % "0.1.0"

Compatibility

Alien can be used with

  • Scala 2.13
  • Java 21 or Java 22

At the time of the release of Java 21, the Foreign Function & Memory API was in the preview stage, so it is recommended to use Java 22 with a final version of FFM.

Docs

More detailed docs can be found here.