Any way to turn off array bounds checking? (Matrix multiplication is so slow!)  
Author Message
agascoig





PostPosted: 2005-3-22 7:14:00 Top

java-programmer, Any way to turn off array bounds checking? (Matrix multiplication is so slow!)
I am just starting to learn Java J2RE 5.0. I coded the matrix library
below and found that the array accessing is really slow since each
access is checked:

http://f1.pg.briefcase.yahoo.com/bc/agascoig/vwp2?.tok=bccV1CVBYRRfg_eF&.dir=/Guest&.dnm=ComplexDoubleMatrixJava.zip&.src=bc

It appears that with gcj and a -f switch I can turn off the array
bounds checking.

Will a JVM ever be smart enough to know that if the array bound is a
constant variable within a loop, that it can multiply and check the
final array index is within bounds before doing the loop, and then only
have to check once? It seems stupid to me that a general Matrix isn't
included in the Java class libraries. Anybody have a better general
Matrix library in Java?

Also, a newbie observation, that Double (capital D) didn't get passed
as a reference. Why not? This seems dumb to me, as all other objects
seem to get passed by reference.

 
Raymond DeCampo





PostPosted: 2005-3-22 11:44:00 Top

java-programmer >> Any way to turn off array bounds checking? (Matrix multiplication is so slow!) email***@***.com wrote:
>
> Also, a newbie observation, that Double (capital D) didn't get passed
> as a reference. Why not? This seems dumb to me, as all other objects
> seem to get passed by reference.
>

To be pedantic, a reference to the object instance is passed by value.

So that means you can invoke methods that change the object instance and
the object instance is changed for the caller as well.

But you cannot change the reference to point to a difference reference
and expect that to register with the caller.

For example (not compiled),

public class Example
{
public static final String NL =
System.getProperty("line.separator");

public static void example(StringBuffer buf, Double d)
{
buf.append("d = ").append(d).append(NL);
d = new Double(2.78);
buf.append("d = ").append(d).append(NL);
}

public static void main(String args[])
{
StringBuffer buf = new StringBuffer();
Double d = new Double(3.14);
example(buf, d);
buf.append("d = ").append(d).append(NL);
System.out.println(buf.toString());
}
}

The output should be:

d = 3.14
d = 2.78
d = 3.14

HTH,
Ray

--
XML is the programmer's duct tape.