Hi,
I'm not posting specific code for this problem, because the problem keeps happening with lots of variations I've thrown at it, and even completely different programs I've written!
The general problem is that I'm trying to make an array of all prime numbers under 10000000. (Why? Blame projecteuler.net .) I had to make it in parts, save it to a file, and run the program again with the next set of numbers to test for primality dozens of times, because after about 300,000 numbers it would simply freeze up. The first 100,000 or so would go by at ridiculous speed. There was nothing wrong with the code, it all worked, I just had to only give it 200,000 numbers at a time, then start it again! I thought maybe it was just that primes really are that much trouble, but after I finally got the array built I wrote a program to simply read the array and print it all to the screen one number at a time. The same thing happened! After about 300,000 (though it would sometimes get as far as 500,000) the program would simply freeze up and refuse to move again! The array's all there - I can ask it to start at a later point, and it will read about 300,000 from there - it just keeps freezing. I should mention that it starts slowing down and jumping before freezing up completely.
To be completely clear, I was having the program read the array with a for loop. Something like:
So, my question: Could the problem be that my array's simply too big? To big even to read?? It that a problem with java, or is my computer just getting slow? Any ideas on how I can fix this? It starts running extremely quickly, then it seems to just start tripping over it's own feet.for (int i = 0; i < primes.length; i++){ System.out.println("" + primes[i]); }