1000000000 array input in java -


i trying test algorithm needs 1,000,000,000 array input.

scanner scanner = new scanner(new file("999999998.txt")); int[] tall = new int[1000000000]; int = 0; while (scanner.hasnextint()) {     tall[i++] = scanner.nextint(); } 

this exception thrown:

exception in thread "main" java.lang.outofmemoryerror: java heap space 

you're trying create (roughly) 4g array , it's big fit in heap (one billion 4-byte integers).

most likely, if want way, you're going need 64-bit java running on 64-bit operating system (and possibly large amount of physical memory performance), , increasing heap size larger default (such java -xmx6g or similar).

or, if algorithm able operate on data in sections, may better option.

so, if you're summing items in file, can bring them in thousand @ time add them running total. that's not going easy if there's lot of random access of sorts of different integers but, in case, possibly create array on disk , use caching/lru interface ensure load in what's needed @ given point.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -