• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Optimizing Code for Chess

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic