I've to implement a render engine (based on ray tracing) for some course (in Java). A few classes are already given (but I'm free to change everything I want). There're a few Matrix/Vector kind of classes which all use seperate variables for each element. For a 4x4 kind of matrix, it looks ugly and seems to me anti object-oriented. I would use a 2D-array. But Java automatically does a bound check. If I use the arrays instead of the seperate variables could this effect the performance in a serious way? (I know that performance and Java do not always match, but It has to be in Java.) Or is it possible to turn off this safety feature?

有帮助吗?

解决方案

Java indeed checks array bounds automatically. This is good and does not have any performance impact.

I know that performance and Java do not always match, but It has to be in Java.

This is true and is not true. Java indeed is compiled to byte code that is then being interpreted. However java has a lot of features that optimize your code including Just in time compiling, so in some tests java runs faster than native code.

And the last point: read about Premature optimization is the root of all evil

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top