Als Antwort auf:/In reply to: Re: Huge memory leak in my chess engine (new at C++) geschrieben von:/posted by: Sune Fischer at 27 March 2004 11:06:49:
Another possibility is calling a function with large auto objects recursively and passing them also by value in a struct. I have seen a chess program that did this and was at 700MB by depth 4.Upon reading your question again, I see that you probably isn't doing dynamicHi,
I am a Java programmer, but I found out when I created a chess engine in Java, that it is a very slow language. So I decided to start program my chess engine in C++ instead. Well, I got through everything fine. I now have a fully functional chess program (without AI yet).
I then made a simple AI with a simple MiniMax algorithm and an evalulate() function that just returns white_material-black_material. It compiled and ran without errors. Now, I noticed (I'm sure you programmers are all laughing at me right now) that after I call the function three times, all of my RAM and VM is used up, and the program crashes. My first thought was: Gee, I guess this must be one of those C++ memory leaks.
My first way to solve the problem was to take all temporary variabled used inside of my MovePiece, AllMoves, and UndoMove functions and put them inside of my Board class, so that they would not be created 100,000,000 times during my MiniMax function. Unfortunately, that didn't work, and free(void *pointer), and delete, and delete[] all give me errors. What should I do? Thanks!!
Steve
allocation.
Just to be clear, this here is fine:
int search(....) {
Move move_list[256];
...
return score;
}
while this is strictly forbidden:
int search(...) {
Move *move_list = new Move[256];
...
return score;
}
The last one does not clean up the move list, and will create a new list at
every node!
Use the first method and it should be fine.
-S.
my ftp site