• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Expanding memory

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

CR
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run java -X for a list of non-standard options including -Xmx and -Xms.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Thanks
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Saloon Keeper
Posts: 4007
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic