Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java and C++ Shared Memory

I have a C++ piece of code that creates shared memory. Is it possible to write Java Code which can read the memory created by the C++ code unless using JNI. By the way I am using Windows OS.

like image 496
Yavuz Avatar asked Feb 28 '13 07:02

Yavuz


People also ask

Does Java support shared memory?

In order to maximize the performance of your Java applications, InterSystems IRIS offers a Java shared memory connection. A shared memory connection allows both the client and the database to share the same memory on their host machine. This shared memory is temporary, and it is backed up by virtual memory.

How to create shared memory in Java?

Two functions shmget() and shmat() are used for IPC using shared memory. shmget() function is used to create the shared memory segment, while the shmat() function is used to attach the shared segment with the process's address space.

What is shared memory in C++?

So, shared memory provides a way by letting two or more processes share a memory segment. With Shared Memory the data is only copied twice – from input file into shared memory and from shared memory to the output file. SYSTEM CALLS USED ARE: ftok(): is use to generate a unique key.


2 Answers

See MappedByteBuffer. It's the standard Java class to read & write shared memory. I use it a lot. Yes, you can use this to communicate with any program written in any language which uses shared memory, and it's all very standard Java, no JNI.

like image 59
Tim Cooper Avatar answered Sep 21 '22 10:09

Tim Cooper


Yes, you can use code project :code project

like image 44
Addict Avatar answered Sep 21 '22 10:09

Addict