Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Variable memory usage?

Thread view: 
Jan Krumsiek - 22 Apr 2006 10:01 GMT
Hi.

My program needs a variable amount of memory, depending on the user's file
input. Is there any way to tell the VM to use as much memory as needed in
general?

I do not want to create a starting script for each memory setting
(-Xmx128m, -Xmx256m etc.etc.) for the user.

One way seems to be the "-XX:+AggressiveHeap" setting but I don't know if it
is suitable for a program on standard desktop machines.

Regards,
Jan
Thomas Hawtin - 22 Apr 2006 16:04 GMT
> My program needs a variable amount of memory, depending on the user's file
> input. Is there any way to tell the VM to use as much memory as needed in
> general?
>
> I do not want to create a starting script for each memory setting
> (-Xmx128m, -Xmx256m etc.etc.) for the user.

-Xms will set the minimum memory usage. The JVM doesn't have to use all
the memory allowed by -Xmx. However, with -server the SoftReference
behaviour is based on maximum rather than currently allocated memory.

Memory allocated by NIO allocateDirect methods does not count towards
the heap size, but may be limited and isn't garbage collected directly
(nor can you explicitly deallocate it).

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Jan Krumsiek - 23 Apr 2006 01:44 GMT
Hello Thomas.

> -Xms will set the minimum memory usage. The JVM doesn't have to use all
> the memory allowed by -Xmx. However, with -server the SoftReference
> behaviour is based on maximum rather than currently allocated memory.

The problem is that I do not know which value to use for -Xmx as I don't
know the amount of physical memory on the client machines.

I didn't really get your point about the -server command line option.

Regards,
Jan
Chris Uppal - 23 Apr 2006 10:11 GMT
> > -Xms will set the minimum memory usage. The JVM doesn't have to use all
> > the memory allowed by -Xmx. However, with -server the SoftReference
> > behaviour is based on maximum rather than currently allocated memory.
>
> The problem is that I do not know which value to use for -Xmx as I don't
> know the amount of physical memory on the client machines.

You could incorporate that knowledge into whatever code launches your Java
program.  For instance if that is a shell script, then the script could
interrogate the OS (in a system dependent way) and choose flags to the "java"
program appropriately.  Alternatively you could write your own replacement for
"java" / "java.exe" which did the same thing in C.  Lastly you could ask the
user as part of installation (with an option change it later) and stuff the
supplied value into some file which is read by the launcher (not the Java
program).

> I didn't really get your point about the -server command line option.

I assume Thomas means that the server JVM (invoked by -server command-line
flag) uses the supplied maximum to determine how much memory it should allow
soft-references to consume.  (Recall that soft refs are used to implement
caches, where data is kept in memory in case it is needed later, but which can
be thrown away if the JVM finds that it doesn't have enough memory for more
necessary work).

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.