473,395 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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/...va.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.

Jul 18 '05 #1
1 4165
ag******@yahoo.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.
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Michael Bader | last post by:
Hi, I'm currently working on a matrix multiplication code (matrix times matrix), and have come along some interesting/confusing results concerning the running time of the (apparently) same...
6
by: Flip | last post by:
I'm reading the O'Reilly's Progamming C# book and I have a question about array bounds checking. On page 174, near the top, they show an example where c# does indeed to array bounds checking cause...
1
by: noleander | last post by:
Hey. I'm new to Visual C++. I've got a large application, and I need to make sure all array accesses are within bounds. Back on Unix we had a tool called Purify that detected array-out-of-bounds...
7
by: VijaKhara | last post by:
Hi all, Is there any method which can implememt the matrix multiplication faster than using the formula as we often do by hand? I am writing the following code and my matrice: one is 3x40000 and...
6
by: amitsoni.1984 | last post by:
Hi, Is there any direct function for matrix multiplication in Python or any of its packages? or do we have to multiply element by element? Thank you, Amit
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
7
by: polas | last post by:
Afternoon everyone. I have a quick question about standard C. Generally speaking, in my experience, whenever one accesses an array there is never any bounds checking done (either statically...
1
by: Sozos | last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void...
8
by: joegao1 | last post by:
can some one give me a hint? I want to program the code for matrix multiplication with as less arithmetical / multiplication operations as possible. my task is to calculate the matrix...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.