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



Chris Uppal wrote:
> 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.

Ah, thanks for the heads up.

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

Erm, strictly speaking copying becomes relatively cheaper (and thus
neglectible) if the op is worse than O(n), doesn't it? Anyway, even if
the op is O(n) you could neglect copying - from a theoretical perspective
(O(n) = O(2n)). It might be different in practice if arrays are huge (mem
allocation overhead) or if they are small and there are many invocations.

Kind regards

robert

.



Relevant Pages

  • Re: To increase speed on manipulating big arrays in Java with minimal bounds checking, ...
    ... >> You could always write custom array operations in JNI. ... > I'm not sure whether array accesses via JNI actually bypass bounds checks. ... Also note that it is very unlikely that the overhead of copying (if it happens ...
    (comp.lang.java.programmer)
  • [opensuse] RAID5 hangs
    ... I was happy copying over my data to a new array of 4x500GB and it ... Active Devices: 4 ... Number Major Minor RaidDevice State ...
    (SuSE)
  • Re: copy of very large files freezes system
    ... >> Copying lots of small files isn't blindly ... Direct Memory Access, yes the memory could be the problem. ... P.s. the source drive is an adaptec 2410S based raid array. ... I'm suspecting problems with the adaptec controller or ...
    (comp.os.linux)
  • Re: Array.Clear vs List<>.Clear
    ... so every time you add one element over the List.Capacity, the it will create a new array, copy the elements, add the new item and then destroying the old array. ... default size starts out at 4 elements, and each time you exceed the capacity of the list, the newly allocated storage has double the previous capacity. ... It's true that for smaller lists, there are more allocations, and so the copying is a larger part of the overall time cost. ... But then, for smaller lists, the total time cost is significantly lower anyway, so that proportional difference isn't really a big deal. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: set double array to 0.0
    ... >> appropriate copying. ... >> correct data versus a memmove? ... >> the memory overlap or not?! ... > You are quite happy with that array, need it to be an array because ...
    (comp.lang.c)