Efficient System.arraycopy on multidimensional arrays

arrays, java

Solution

`System.arrayCopy` is likely the fastest way to copy an array, but it does not make deep copies.

It also cannot do the more complex example in your second question.

Problem

I'm aware that a common performance refactoring is to replace simple `for`'s by `System.arraycopy.` I want to ask about: When exactly does system.arraycopy begin to make sense (considering it's a native method call). Does copying small things say, < 32 have any advantage? Is it my impression, or is it not simply possible to copy (efficiently) a cycle like this with arraycopy: ``` for (int j = 0; j < 2; ++j) { vpr[m][s + j][i] = vr[j]; } ```

Original source