How should I deal with a very large array in Java?

前端 未结 7 1784
情深已故
情深已故 2021-02-04 13:48

I have an algorithm which currently allocates a very large array of doubles, which it updates and searches frequently. The size of the array is N^2/2, where N is the number of

相关标签:
7条回答
  • 2021-02-04 14:32

    If the problem is that you are running out of memory, the simple solution is to upgrade your hardware with more memory, increase the Java heap size and/or switch to a 64-bi5t JVM.

    On the other hand, if you are running against the Java limit on the size of arrays, you could go down the ByteBuffer route, or you could switch to using an array of arrays. The later is Sun's suggested workaround.

    With the array of arrays approach you could (in theory) cope with values of N close to 2**31. In practice your limit will be determined by the amount of physical memory you have, and the amount that can be addressed using your combination of OS / JVM.

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