![]() |
|
|
|
#1 |
|
Posts: n/a
|
Hello,
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 not really satisfy me. Regards, John |
|
|
|
#2 |
|
Posts: n/a
|
> Hello,
> > 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). In java, the easier way to share the memory between 2 programs is to use 2 threads in 1 JVM. Moreover, the java language contains a built-in mechanism to access to the objects and their data wrt the concurrent threads (the "synchronized" keyword). In C++ it was hairy, in Java it is smooth and easy. Vincent Cantin |
|
|
|
#3 |
|
Posts: n/a
|
In general you have to use C/C++ and JNI to create a shared memory
segment. Then there is the issues of moving object state into and out of memory, this can be pretty complex to do and get it right. Most of the time you can design around the problem with RMI or standard network programming. The other route is to use a commercial product such as Gemstone Systems Facets or Gemfire product lines which have already solved the shared memory issues.. V > > 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). > |
|
|
|
#4 |
|
Posts: n/a
|
On 8 Mar 2005 08:10:14 -0800, wrote:
> 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). Not really the same as shared memory, but maybe Java Spaces would provide a more Java-like solution to whatever it is you're trying to do. /gordon -- [ do not email me copies of your followups ] g o r d o n + n e w s @ b a l d e r 1 3 . s e |
|
|
|
#5 |
|
Posts: n/a
|
One link on memory objects in NIO. I skimmed it but the mem does not
seem mapped to shared mem; i.e. the memory cannot be accessed by other apps AFAICT. ? http://www.developer.com/java/other/...0936_1548681_1 TimJowers |
|
|
|
#6 |
|
Posts: n/a
|
I thought maybe RandomAccessFile might be a memory mapped file but JB
pointed out this is not so in the thread: "How to initialize a big (String-)Array fast?". I have not found a memory mapped file class in Java. What would be nice is a RAMFile and if this same memory can be accessed by name from CreateFile(). That would be nice. This would be a very good assignment for a graduate level Java class: "Create a Java RAM File object that uses native APIs to provide a memory mapped file." |
|
|
|
#7 |
|
Posts: n/a
|
wrote:
> I thought maybe RandomAccessFile might be a memory mapped file but JB > pointed out this is not so in the thread: "How to initialize a big > (String-)Array fast?". I have not found a memory mapped file class in > Java. You would want to consider the java.nio.MappedByteBuffer class, which does represent a view of a memory-mapped file. -- John Bollinger |
|
|
|
#8 |
|
Posts: n/a
|
One thing to keep in mind is whether it can be shared between
processes, which I don't think you can do with java.nio.MappedByteBuffer. The other issue with this is that for small files it probably isn't an issue but large files will consume a significant amount of the virtual address space that an application may need( same issues exist for users of shared memory). V John C. Bollinger wrote: > wrote: > > > I thought maybe RandomAccessFile might be a memory mapped file but JB > > pointed out this is not so in the thread: "How to initialize a big > > (String-)Array fast?". I have not found a memory mapped file class in > > Java. > > You would want to consider the java.nio.MappedByteBuffer class, which > does represent a view of a memory-mapped file. > > -- > John Bollinger > |
|
|
|
#9 |
|
Posts: n/a
|
Hello,
Thanks; I am familiar and had used many times concurrent threads and "synchronized" in Java. The thing is , I want to share memory between 2 threads/processes , one in Java and one in "C". There is of course the JNI solution; I am currently using it; the thing is that when you call a JNI method from Java , and there is some problem in the "C" code (like a pointer which is not handled right and ,for example, is incremented so that it points to a non-valid address) it is sometimes difficult to trace. Of course you can use bound checkers and other memory debugging tools, but it is a sometimes cumbersome. Especially , when there is a problem with a pointer as I depicted above, the crash will be sometiomes in the Java part (so it seems to me ) ; As I understand , when you allocate memory in the JNI "C" method, it gets it memory from a memory manager of the "c" compiler , but there is an upper memory layer of Java which controls it somehow. (I am NOT sure about it; memory managers allocatiOn algorithms are complex , and I don't know much about Java memory manager since Sun's code is not an open source ). If the two threads need only a little in common (lets say one should only pass a string of 10 chars to the second ("C") code, as it is in my case , it seems to me that using shared memory can be a solution (if it is an option at all). It may be a little less efficemt than using JNI, but it can be easier to maintain/debug. Regards, John Vincent Cantin wrote: > > Hello, > > > > 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). > > In java, the easier way to share the memory between 2 programs is to use 2 > threads in 1 JVM. > Moreover, the java language contains a built-in mechanism to access to the > objects and their data wrt the concurrent threads (the "synchronized" > keyword). In C++ it was hairy, in Java it is smooth and easy. > > Vincent Cantin |
|
|
|
#10 |
|
Posts: n/a
|
> One thing to keep in mind is whether it can be shared between
> processes, which I don't think you can do with > java.nio.MappedByteBuffer. This is a abstract class, not final, so you can redefine the implementation of the functions in a subclass written by your own (.. using JNI to access the shared memory segment). |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OCZ 6GB Triple-Channel 1333 MHz DDR3 Memory Kit | Ian | Front Page News | 0 | 02-16-2009 12:27 PM |
| memory upgrade | -D- | A+ Certification | 1 | 02-03-2007 12:01 AM |
| Re: What memory to use? | me | A+ Certification | 0 | 12-14-2004 02:33 AM |
| Re: Memory stick question | Nildram | A+ Certification | 1 | 01-14-2004 01:41 PM |
| Half memory: lost? | Joe | A+ Certification | 4 | 09-04-2003 07:57 PM |