Maximum size matrix without getting OutOfMemory error?
Admittedly, I could have figured it out through trial and erro开发者_运维问答r, but I would also like to know whether or not this number varies and how (computer performance, other data structures present, compiler type, etc.). Thanks!
You will need to increase you JVM heap size if you run out of memory, read this. Nothing you can do if your matrix requires a lot of memory (if there is no memory leaks) other than increasing the heap size.
You can change the size of your matrix as large as you want (but not bigger than the maximum value of integer which is used as index) if you have enough memory. Integer is 32bits so, you have the maximum theoretical limit there.
While the maximum array size is the limited by a 32-bit signed value. i.e. 2^31-1 or about 2 billion, most matrices are implemented as two dimensional arrays so the maximum size is 2 billion * 2 billion. You could use float or double, but if you had a matrix that big your accumulated rounding error would be enormous. ~ 2^62 bits which is more than the accuracy of a double, so you would have to use BigDecimal in any case. Say the each cell took about 128 (2^7) bytes of memory you would need a total of 2^69 bytes or 512 Exa-bytes (32x the theoretical limit of the memory a 64-bit processor can handle)
it also depends upon the memory of your machine and how much memory you allocate for the process using -Xmx.
精彩评论