Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

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

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.