aspose file tools*
The moose likes Game Development and the fly likes Optimizing Code for Chess Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Optimizing Code for Chess" Watch "Optimizing Code for Chess" New topic
Author

Optimizing Code for Chess

Ashish Schottky
Ranch Hand

Joined: Dec 29, 2009
Posts: 93
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

Joined: Oct 02, 2003
Posts: 11479
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ashish Schottky
Ranch Hand

Joined: Dec 29, 2009
Posts: 93
@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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Optimizing Code for Chess