4

I'm trying to create some memory in C++ and access it in Java. On the C++ side I know that I can use shm_open and mmap to obtain a memory region and write some data into it. But, how can I open the memory-mapped file on the Java side? Someone suggested to use MappedByteBuffer but how can that access the "path" provided to shm_open (it only exists in memory so cannot initialize a File from it). Can I do this without using JNI?

4
  • The functions you mention seem to indicate a Linux environment. Is that so? Or do you require more portable solution? Anyway, I suggest using more well established interprocess communication. Why not just use sockets. Commented Mar 30, 2016 at 4:19
  • possible duplicate stackoverflow.com/questions/32440527/… Commented Mar 30, 2016 at 4:27
  • @Cheersandhth.-Alf yes it's linux environment. Doesn't have to be portable. We want to use shared memory for performance reason (to avoid copying). Commented Mar 30, 2016 at 4:35
  • @BevynQ seems like the link you posted doesn't solve my issue. It's also windows based. Commented Mar 30, 2016 at 4:36

1 Answer 1

2

On Linux environment shared memory has special memory segment:

/dev/shm

Name provided in shm_open (e.g. "elo320") is used to create file

/dev/shm/elo320

This path can be used in Java.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.