Getting physical memory

C

Chris

Is it possible to know how much physical memory there is in a machine?

Runtime.getRuntime().totalMemory() returns the amount available to the JVM,
not the amount in a machine.
 
J

Jesper Nordenberg

Liz said:
the dos command "mem" should do it
call it via NJI

"mem" only reports the memory available to DOS programs (for example
my 2k machine reports 1 MB of RAM). There are much better functions to
use in the Win32 API. Besides, the OP didn't write that he uses a
Windows machine.

There is no way to tell the amount of physical memory in pure Java.
Why do you need that information?

/Jesper Nordenberg
 
R

Roedy Green

"mem" only reports the memory available to DOS programs (for example
my 2k machine reports 1 MB of RAM). There are much better functions to
use in the Win32 API. Besides, the OP didn't write that he uses a
Windows machine.

If you can find any console mode app to tell you, exec it and capture
the result. See http://mindprod.com/jgloss/exec.html
 
R

Roedy Green

"mem" only reports the memory available to DOS programs (for example
my 2k machine reports 1 MB of RAM). There are much better functions to
use in the Win32 API. Besides, the OP didn't write that he uses a
Windows machine.

If you can find a WinApi call to tell you want you want, you can write
a tiny bit of JNI to get at it.
http://mindprod.com/jgloss/jni.html

See http://mindprod.com/products.html#PENTIUM for some sample JNI code
you could use as a model.

It might be part of the JConfig library. See
http://mindprod.com/jgloss/jconfig.html
 
L

Liz

Roedy Green said:
If you can find a WinApi call to tell you want you want, you can write
a tiny bit of JNI to get at it.
http://mindprod.com/jgloss/jni.html

See http://mindprod.com/products.html#PENTIUM for some sample JNI code
you could use as a model.

It might be part of the JConfig library. See
http://mindprod.com/jgloss/jconfig.html

Ok, then figure out what the memory is using whatever and
provide it to the program via -D on the command line. The
program can get it through properties.

java -DMEMORY=55 myjavaprog
 
C

Corey Brown

Liz said:
Roedy Green said:
"mem" only reports the memory available to DOS programs (for example
my 2k machine reports 1 MB of RAM). There are much better functions to
use in the Win32 API. Besides, the OP didn't write that he uses a
Windows machine.

[ SNIP ]
Ok, then figure out what the memory is using whatever and
provide it to the program via -D on the command line. The
program can get it through properties.

java -DMEMORY=55 myjavaprog

And if the Java program is long lived, then what?
 
L

Liz

Corey Brown said:
Roedy Green said:
On 8 Jun 2004 04:16:21 -0700, (e-mail address removed) (Jesper Nordenberg)
wrote or quoted :

"mem" only reports the memory available to DOS programs (for example
my 2k machine reports 1 MB of RAM). There are much better functions to
use in the Win32 API. Besides, the OP didn't write that he uses a
Windows machine.

[ SNIP ]
Ok, then figure out what the memory is using whatever and
provide it to the program via -D on the command line. The
program can get it through properties.

java -DMEMORY=55 myjavaprog

And if the Java program is long lived, then what?

What is your question?
 
C

Chris

There is no way to tell the amount of physical memory in pure Java.
Why do you need that information?

Because I want to use NIO's MappedByteBuffer to map files to memory. A
little experimentation shows that if you map too many files or files that
are too big you'll get error messages. So I want to know what the limits
are.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top