3

When I read this link Java Criticism. At the section Large Array. There is two point I don't understand :

Java also lacks true multidimensional arrays (contiguously allocated single blocks of memory accessed by a single indirection), which limits performance for scientific and technical computing

In C, I know that multidimensional arrays is just a contiguously memory of element. So, as section above, each row in Java is an object, and multi rows just like multi objects, and they're not contiguous in memory, right ?

Java has been criticized for not supporting arrays of more than 231 - 1 (about 2.1 billion) elements ... Arrays must be indexed by int values... An attempt to access an array component with a long index value results in a compile-time error

Does this mean, if we can access an array component by long integer, the array size can be bigger ? And in that case, so, this still limit size of array is size of long, right ?

Thanks :)

1
  • You could always use multidimensional lists instead to eliminate the size limitation! Commented Oct 6, 2012 at 9:34

1 Answer 1

3

... each row in Java is an object, and multi rows just like multi objects, and they're not contiguous in memory, right ?

That is correct. A Java multi-dimensional array is an array of arrays, with each array represented as a separate object.

Does this mean, if we can access an array component by long integer, the array size can be bigger ?

No. The maximum size of a Java array is 2^31 - 1 elements.

The JLS says this at JLS 10.4:

"Arrays must be indexed by int values; short, byte, or char values may also be used as index values because they are subjected to unary numeric promotion (§5.6.1) and become int values.

An attempt to access an array component with a long index value results in a compile-time error."


In short, the page that you linked to is correct in pointing out that Java is not ideal for applications that require the use of very large arrays. (It is possible to work around the limitations, but you can't do it cleanly without wrapping the underlying array representation as an object. And that has performance implications, and means that you can't use [...] syntax for indexing.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.