permaculture playing cards
The moose likes Java in General and the fly likes Expanding memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Expanding memory" Watch "Expanding memory" New topic

Expanding memory

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Hi there, I was wondering if it was possible to expand the memory in java.
Basically I am writing a chess program, and I need to use some very large arrays with millions of entries.
When I go past initializing 10,000,000 (long) members of an array,
I get a java.lang.OutOfMemoryError.

Is it possible (inside of program's code) to give it more memory, to avoid this happening?

Thanks for any help.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
Yes, you can increase the memory allocation to the JVM. I have never tried myself, but found this thread, where they go on aout the Xmx option. See whether that helps.

Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Run java -X for a list of non-standard options including -Xmx and -Xms.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Excellent, thanks

I managed to fill an array of 50million long values, by using:

However... ideally I would like to make this work in an applet,
but we cannot execute a program like that in an applet, its automatic.

Is it possible to do what I've done above inside the program?
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
I don't know if you can, I've never witten applets so I can't help you there. The first thing I would question is why a simple Chess game needs so much memory. Perhaps re-examining your design would be energy better spent.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Who said it was a simple game?
Chess is a very difficult game to program.
Have you seen deep blue? That supercomputer weighs a quarter of a ton,
so you can assume it has a lot of things stored in memory.

Anyway... I'm trying to get some transposition tables made.
My program is analyzing around 2 million positions per second,
and to give better functionality you should save positions that have
been searched already, so that you do not need to search again.

Perhaps I can make do with just a million stored positions, I'm
not sure yet, its related to zobrist keys, which define a position.
Anyway, theres far more positions than zobrist keys.

Basically, the more space I have, the more positions I can store, which
means I do not have to rewrite over old ones, and it will make the
search quicker, and produce a better playing program.

Bet you wish you never asked now
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

It might be better to build a caching mechanism since in the end, memory is finite. If its conceivable (and it sounds like it might be) that your algorithm will use up all available memory, you might want to redesign parts of it to break up data into small sets. Its what I've done on large machine learning projects where individual tasks can take hours at a time.

[OCA 8 Book] [Blog]
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

You definitely want to optimize based on the available memory. Alternately, you can refuse to run unless enough memory is granted up front rather than waiting 1/2 hour into deep calculation to tell the user you can't continue.

Check the system veriables should tell you how much memory is available. Memory can only be expanded by the user not the programmer. Lest the programmer suck up all the memory for himself and set the priority and resource levels for programs on the end users computer...
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'd be tempted to make up some kind of swapping to disk with largish chunks and random access files. But I just read the difference in speed is about the same as an e-mail from NY to London via satellite vs postal mail by ship.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
All that been said, you can control the runtime settings of the JRE by means of the ControlPanel application installed in the bin directory of your JRE.

In Windows you can have direct access to this application from the Control Panel, there you will see a Java icon. In Linux you can run the ControlPanel application directly from a terminal window.

In this application (ControlPanel) there is a tab named Java, there you wil find a Applet Runtime Settings where you can set JVM specific options, and properties for your installed JREs.
I agree. Here's the link:
subject: Expanding memory
jQuery in Action, 3rd edition