Whats wrong with arrays in Java?

arrays Java wrong
0
Posted

Whats wrong with arrays in Java?

0

An array is a low-level idea exposed in a high-level language. In a low-level language such as C, an array is just a blob of memory. Accessing elements is very fast, because you’re just multiplying the size of an element (typically a power of two) by the index and adding the result to the start. By contrast, the memory model in Java is intended to prevent unsafe accesses, so no pointer arithmetic is used. Activities that do pointer arithmetic in the background are subjected to additional tests. Any lookup of an array value requires a range check. A na├»ve Java compiler inserts a test around each array access to check whether the index is in the permitted range. A modern compiler or VM does a lot of static analysis to try to remove these checks. How is this problem caused by choosing the wrong abstraction? A few years ago, a group at IBM tried modifying Java to require arrays to be accessed via index sets. The only operations you could perform on index sets were those from set theory; th

Related Questions