Making a very large Java array

后端 未结 15 2160
鱼传尺愫
鱼传尺愫 2020-12-03 08:57

I\'m trying to find a counterexample to the Pólya Conjecture which will be somewhere in the 900 millions. I\'m using a very efficient algorithm that doesn\'t even require an

相关标签:
15条回答
  • 2020-12-03 09:19

    Depending on how you need to access the array, you might find a RandomAccessFile will allow you to use a file which is larger than will fit in memory. However, the performance you get is very dependant on your access behaviour.

    0 讨论(0)
  • 2020-12-03 09:23

    You could define your own class which stores the data in a 2d array which would be closer to sqrt(n) by sqrt(n). Then use an index function to determine the two indices of the array. This can be extended to more dimensions, as needed.

    The main problem you will run into is running out of RAM. If you approach this limit, you'll need to rethink your algorithm or consider external storage (ie a file or database).

    0 讨论(0)
  • 2020-12-03 09:25

    Use a memory mapped file (Java 5 NIO package) instead. Or move the sieve into a small C library and use Java JNI.

    0 讨论(0)
提交回复
热议问题