Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method takes longer each time

 
Masha Stekker
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I'm still stuck with my extending loops, despite a lot of help already received on this forum.
I've narrowed down the problem somwhat;
Each time the method that displays the arrays gets called it takes longer to complete. This is bad enough that the program slows down to a complete halt. And its supposed to repeat the loop 1000 times for arrays of 100x100, I'm just testing it at 100 times for arrays of 50x50.
It seems as though it needs to check through more & more information each time. But I dont understand why this might be.
I've added little print out comments at the beginning and end of the methods so that one can see how they slow down.
If I comment out the method that creates and initialises the arrays that get displayed, this makes no difference: so it cant be that I'm re-initialising the arrays and that this takes up more memory. Can it? I'm not sure.

[ April 17, 2004: Message edited by: Jim Yingst ]
 
kelly devon
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check ur code againi think u reinitialized row of array2 twice i saw a repeat of that check it out and try again
 
Masha Stekker
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um.
Cant spot it. Whereabouts?
ALso, if I sidestep the whole "display in a scrollable text area" then the thing seems to work (if I simply print the arrays out in MSDos window.)
Why would displaying it in the window make the loops slow down? Is it using up memory somehow the way I'm doing it?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Masha. I added [code] tags to your post above, since that allows our forum software to preserve the indentation of your code when it's displayed, which makes if more readable. Note that using tabs for indentation is probably a bad idea, as in a web browser it translates into 8 spaces. That's much more indentation than we really need, and it causes your program to use up a lot of horizontal space. Which will make it harder to fit on the screen at once (for people with smaller monitors), which again will make it harder to read. I recommend using spaces for indentation, no more than 4 per level. (4 seems to be the industry standard, though 2 and sometimes 3 are also used).
As for your program - try printing out the value of output after each time you call writeArray(). Look closely at the output from the first few iterations - is it what you expect? How is it different? Is all the output really necessary? Good luck...
 
Masha Stekker
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I THOUGHT it was something like that!
OH COOOOOOL its finally working. Thanks so much for pointing that out to me!
For any other begginers out there that might ever read this, I changed my code so that in the writeArray method, output is set to be an empty string every time the method starts. Then I changed the bit of code that puts the output in the text area from "outputArea.setText(game3.output);" to "outputArea.append(game3.output);" and moved it inside the loop that makes the method call 500 times.
It seems to work! But I must add, that I've thought that so many times now I'll have to test the thing some more before I can really relax.
Thanks also for the tips on indenting - thats been bothering me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic