Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Optimizing Code for Chess

 
Ashish Schottky
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
I have coded a chess game and it has the following part:

The dynamic memory allocation of the array, makes the program run slowly.
So I tried

but then it gives me a bug as there are no other moves which are tried. It seems that no other moves are loaded into the array execept for the first one.
Is there some problem due to memory allocation or the way in which I am accessing it?
here is the code from filter moves()


How can I allocate all the required memory statically?(There is tremendous slow-down due to dynamic memory allocation).
 
fred rosenberger
lowercase baba
Bartender
Posts: 12198
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know that "Move[] total_final_moves=new Move[200]" only allocates space for the pointers to the moves. You don't have the 200 Move objects, just pointers/references to them.

You have effectively created an egg carton that can hold 200 eggs, but it is empty.
 
Ashish Schottky
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Fred: Thanks for replying:
But doesnt this line fill up the array with objects of type Move.
Here ge.filterMoves() return an array of type Move.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic