Determining Physical Memory at install time in order to set JVM heap parms

Can someone tell me a Windows BAT command or send me a simple Windows program that will return the real physical memory of the computer it is running on?

WHY I WANT THIS:

I know that I can set JVM -X parameters in order to set initial and max heap sizes. What I want to do is figure out what to set those values to.

I have an installable Java application. Most of my users don't know it is in Java, and don't care. Most don't know what heap is and don't even know how much RAM they have in their computer.When my installer program (Install Anywhere) runs it can set the default JVM parameters to whatever I want them to be.

What I would like to do is to check some Environment variable, or system property either by running a program or shell program that returns the physical memory size of the real machine. From that I can calculate what the ideal settings will be for this particular user, and I'll have the installer set those values so that when my program runs the JVM will have the optimal sizes for this computer.

My initial target OS is Windows, but ultimately I want to support Unix and Mac as well. I'm quite able to do special casing for each OS. If someone has a solution for finding the physical memory in Unix and Mac as well, I would love to hear from them.

Please email me:

mail-to:scott.mcgregor@data-digest.com

Scott McGregor

Vice President of Engineering and Product Marketing

Data Digest Corporation

10 El Camino Real, Suite 200

San Carlos, CA 94070

scott.mcgregor@data-digest.com

Download a free preview release of Business Navigator 5 at:

www.data-digest.com/index103.html

The fastest way to predict the future.

[1762 byte] By [mcgregorDD] at [2007-9-26 9:22:47]
# 1
I'm running windows NT. I go into a DOS box and type "mem", and get lots of info.Hope this helps.
bschauwe at 2007-7-1 20:41:01 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

> Hope this helps.

Not really:

C:\>mem

655360 bytes total conventional memory

655360 bytes available to MS-DOS

634400 largest executable program size

1048576 bytes total contiguous extended memory

0 bytes available contiguous extended memory

941056 bytes available XMS memory

MS-DOS resident in High Memory Area

C:\>

so, of the 256M that i've got, mem tells me about 640K of it.

-ed

eporter at 2007-7-1 20:41:01 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

Hi,

I have run into the same requirement here. I have a solution that I have implemented in PowerBuilder, but the same can be replicated in java. Unfortunately this is only for windows and I don't like it as it makes my java code platform dependant.

use the following subroutine from kernel32.dll

SUBROUTINE GlobalMemoryStatus(ref gstr_memory mem2) LIBRARY "Kernel32.dll"

The gstr_memory is a structure defined as follows:

m_length unsignedlong

m_loaded unsignedlong

m_totalphys unsignedlong

m_availphys unsignedlong

m_totalpagefile unsignedlong

m_availpagefile unsignedlong

m_totalvirtual unsignedlong

m_availvirtual unsignedlong

Use the last 6 attributes that reflect the physical memory, pagefile and virtual memory on the m/c.

Hope this helps,

Durga

dprasad_turaga at 2007-7-1 20:41:01 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

You could try the following if you can get the appropriate MS jar

import com.ms.win32.*;

public class zzz

{

public static void main(String s[])

{

MEMORYSTATUS m = new MEMORYSTATUS();

GlobalMemoryStatus(m);

System.out.println("Total Physical Memory : "+Integer.toHexString(m.dwTotalPhys));

System.out.println("Total Available Memory : "+Integer.toHexString(m.dwAvailPhys));

System.out.println("Total Page File : "+Integer.toHexString(m.dwTotalPageFile));

System.out.println("Available Page File : "+Integer.toHexString(m.dwAvailPageFile));

System.out.println("Total Virtual Memory : "+ Integer.toHexString(m.dwTotalVirtual));

System.out.println("Available Virtual Memory : "+ Integer.toHexString(m.dwAvailVirtual));

}

gregambrose at 2007-7-1 20:41:01 > top of Java-index,Java HotSpot Virtual Machine,Specifications...