Powered by Blogger.
Showing posts with label bounds. Show all posts
Showing posts with label bounds. Show all posts

Java - Array Bounds Optimization

Array Bounds Optimization:

In Java technology, all array indexes begin at 0. The number of elements in an array is stored as part of the array object in the length attribute. If an out-of-bounds runtime access occurs, then a runtime exception is thrown.

Array Bounds Example:-

 public class ArrayBounds{
 publ i c void arrayElement ( i n t [ ] myArray ){
 for(int i=0; i<myArray.length; i++)
 System.out.println(myArray[i]);
 }

Notes:-

Array Bounds Optimization can easily performed as a special case of constant propagation. More advanced versions of Array Bounds Optimization will need range analysis.

Array Bounds Optimization is one of the most important optimizations which has to be performed by any Java optimizer. Sometimes, the compiler may even have to rearrange control structures to enable Array Bounds optimizations.