1

I read few articles online but it's not quite clear to me when would you want to have off-heap memory? I understand off-heap memory solution would address GC performance issues. But I am looking for some solid applications/examples where this can be useful. Wondering if you point me to some resources which provides some scenarios where this would truly make sense going off-heap?

Sam K
  • 11
  • 1
  • 4
  • 1
    One purpose is to set up data structures to call methods in native libraries. See some examples here https://stackoverflow.com/questions/69321128/how-to-call-a-c-function-from-java-17-using-jep-412-foreign-function-memory-a/69347525#69347525 – DuncG Oct 27 '21 at 22:14
  • 1
    DuncG is correct. It’s for native calls. Do not try using native memory to improve performance; Java’s memory management is quite good, and you are not going to outdo it. Performance issues are usually due to careless or frequent creation of objects; a common example is building a String in a loop using `+=` instead of using a proper StringBuilder. – VGR Oct 27 '21 at 23:53
  • We have a JavaFX application controlling several different cameras. Having performance improvements in mind we plan to investigate the Foreign Memory API for our use case. It would mean that we allocate the memory (needed for the picture data acquisition) on the Java side and pass it to the cam on initialization. Thereby, we might be able to avoid some of the (cpu-consuming) data-copying. – Michael Marton Nov 22 '21 at 15:01
  • I like this example, an incomplete Java binding to the OpenGL API: https://github.com/jzy3d/panama-gl – gouessej Apr 27 '22 at 11:23

0 Answers0