Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

New Project

Posted by Circuit Negma on January 5, 2009

Created By: Hussein Nosair

Project Scope:

The project focuses on using a shared memory between 2 java programs.


Gathering Info.





Is there someting which may be termed as “shared memory in java” ?
(I mean something which may connect 2 Java processes but is not a
socket ;
something like CreateFileMapping() in windows or shmget/shmat() (Unix
System V IPC) or
shm_open() (Unix Posix IPC).
Googling for “shared memory in java” in groups gave 7 results which did





I have the following problem :
i want to create something similar to windows’ FileMapping.
I have an application in C that had allocated some memory buffer and
now it writes to this buffer every once in a while.
I want this buffer to be available for reading from JAVA applications,
but :
since performance is really an issue here, i don’t want to issue a jni
each time i want my java application needs to access the buffer, (even
if the C application can fire some kind of event)
I would like the java app. call the jni method once, get the shared
memory location and be able to treat it as a buffer as well – with
changes appearing directly as they are seen to the C program.
(For example the Java app. could spin loop on some location in the
shared memory and act as soon the value changes…)
Is there a conceptual problem to accomplish my mission ?
If not ,how can i achieve that ?
thanks in advance.




“Java access to shared memory”


6.4 Java Access to Shared Memory

This discussion is based on the shipped example java-interop, located in your <installdir>\tutorials\sdo directory.

This example illustrates how to access a C++ application’s data in shared memory from a Java application.

6.4.1 Procedure Overview

This tutorial illustrates how to write a class in Java that parses a DataGraph to shared memory, and pass that data back and forth between a C++ application. This includes developing a Java class that declares a native method implemented in C++.

Here is the procedure in more detail:

  1. The Java class creates a DataObject that contains two integers, a and b. It wraps this DataObject into a DataGraph.

  2. then calls to another Java class containing a native method calculateTotal() implemented in a C++ function. This method performs a calculation on the data. Here’s how this works:


    The Interop.calculateTotal() method calls another Java application,, which declares the native method. This class uses the JNI method loadLibrary() to access the implementation of calculateTotal() on the C++ side.

    b. then invokes the native method, which calls InteropCpp.cpp through its interface InteropCpp.h. This is the C++ function that contains the implementation of calculateTotal().

  3. The C++ file InteropCpp.cpp performs the calculation and passes the data back to the Java application

  4. prints the changed values to illustrate the successful cross-platform data exchange.

Before discussing this particular tutorial in more detail, it may be useful to understand how to use JNI in your own applications.





multiple JVM runtimes do not share memory between themselves





1. Two different java programs running in two different user areas
needs to communicate with each other. Can there be anything like a
shared memory. There are considerations, due to which I can
not use a port or a file.

Is there a way to have a shared memory or is there a way, how I
can share an object between two java programs, which are running
in two different user areas.





Keyword search: sharing memory between java programs



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: