-7

I known this probably goes against lots of general rules in programming, but how would you do this? There are two reasons why I am asking this:

  1. I want to attempt to have on app write data to RAM and another to read that same data from RAM.
  2. I want to known because in the near future I will have to optimize a java application.
casperOne
  • 73,706
  • 19
  • 184
  • 253
Andrew delgadillo
  • 714
  • 6
  • 13
  • 24

4 Answers4

5

This question lacks a lot of knowledge about general programming at least from how it's phrased, but what the hell I'll humour the author here.

What you're really asking for is shared memory as a form of IPC (inter process communication). And Java doesn't support shared memory because it's very OS specific. And, if you want to share objects between two processes it's just as easy AND more flexible to use sockets. You seem very concerned about performance without really knowing anything about your program's performance, but sharing data over sockets is just as fast as shared memory for practical purposes. I wouldn't get overly upset that shared memory isn't an option. Not many programs use it anymore now that this thing called the internet showed up.

If you're really twerked over shared memory you can look at Memory Mapped files using NIO. Now that NIO2 is out with Java 7 there might be some other options that have better performance.

chubbsondubs
  • 37,646
  • 24
  • 106
  • 138
  • Ahhhh, this getting a little frustrating, all I want to know is if java can write to RAM that the JVM controls. I really don't care about transferring data between applications. That was just a possible situation, now I see that is not practical – Andrew delgadillo Jul 16 '11 at 15:29
  • 1
    Yes Java can't write to RAM that the JVM controls. Use the new expression to allocate an object in RAM that the JVM controls. String foo = new String("You don't know much about programming do you?") – chubbsondubs Jul 16 '11 at 15:34
  • @Andrew Use a variable? Variables are allocated in RAM. – Marcelo Jul 16 '11 at 15:44
  • @chubbsondubs Dude ... You seem more interested in insulting the OP than giving him an answer! He may not know much about programming but I'm wondering is there something You don't know much about? Just asking ... – Ashkan Kh. Nazary Sep 13 '12 at 07:44
  • 1
    @ashy_32bit what's your point? The question was closed, yes I gave him a snarky answer, but it was a real answer to his question. He just didn't understand it because he doesn't really understand what he's asking about. Read his question number 1, then read his response to me saying he didn't want to transfer data between applications. He clearly asked just that, but he doesn't even understand that's what he's asking. What can I say some people just rub you the wrong way sometimes and the internet makes it easy to scratch that itch. – chubbsondubs Sep 13 '12 at 15:01
  • @chubbsondubs My point is no one is forcing you to come here and experience whatever annoyance it is that you are experiencing. If you feel uncomfortable with these kind of questions, then just pass by. No one comes here to know how they make someone feel. It's your problem that you feel this much irritated not the OP's. – Ashkan Kh. Nazary Sep 14 '12 at 10:51
  • 1
    @ashy_32bit. Yes and no one is asking you to go around dispensing your "advice" about what is appropriate tone either. So you've come here to remind me what? I answered a question with a snarky tone? Oh dear lord I bet that was the first time that happened on the internet. – chubbsondubs Sep 14 '12 at 16:43
  • @chubbsondubs "Yes and no one is asking you to go around dispensing your "advice" about what is appropriate tone either". As a matter of fact, they do. It is not an "advice" I am giving, it is a qualitative observation. Every user is entitled to react to a "non constructive" answer. Or perhaps to adopt your tone, a "useless" answer. Your answer has no technical (=quality) added values in it (except if you consider insults as technical points). SO is a highly technically oriented, objective, welcoming place. Your answer is none. It is "redundant" at best. – Ashkan Kh. Nazary Sep 15 '12 at 13:44
4

Java is not able to read/write to an arbitrary position in the RAM.

If you want to share data between different applications, I recommend using a file or a database.

Marcelo
  • 11,218
  • 1
  • 37
  • 51
2

Here I'm assuming that you'd want to "pass" data between two processes without resorting to write the data to a temporary store like database or a file. The answer would then be: inter process communication. There are a techniques which can be used to implement IPC but the choice depends a lot on your requirements.

Sanjay T. Sharma
  • 22,857
  • 4
  • 59
  • 71
0

It is possible to write directly to the RAM that the JVM controls. However this probably won't be very useful unless both applications on running on the same JVM.

Accessing the physical memory will probably require something outside of Java.