Re: To increase speed on manipulating big arrays in Java with minimal bounds checking, ...



Robert Klemme wrote:

> > [me]
> > You could always write custom array operations in JNI. Otherwise the
> > answer is no (not without a change to the JVM design, which isn't
> > going to happen).
>
> I'm not sure whether array accesses via JNI actually bypass bounds checks.

It does. The way the JNI interfaces work (for arrays of primitive types --
which are the only kind worth considering in this context) the API gives you
(at its choice) either a pointer to the data (which you have to return
explicitly) or a pointer to a temporary copy of the data (which you also have
to return). In either case access to the individual elements is at full memory
speed. There is no need to issue a JNI call for each array access.

Also note that it is very unlikely that the overhead of copying (if it happens
at all) would matter. Copying is O(n), but unless the operation itself were
significantly more expensive than O(n) there would be no point in optimising
it.

-- chris


.



Relevant Pages