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?
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.
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.
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.
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...
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