多维数组高效System.arraycopy [英] Efficient System.arraycopy on multidimensional arrays

查看:148
本文介绍了多维数组高效System.arraycopy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,一个常见的​​性能重构是由 System.arraycopy。来代替简单的

我想请教一下:


  1. 在究竟system.arraycopy开始变得有意义(考虑到它是一个本地方法调用)。是否抄袭小东西说,< 32有什么优势?


  2. 这是我的IM pression,或者是它不只是可以复制(有效的)一个周期是这个样子arraycopy:

     为(INT J = 0; J&2; ++ j)条{
           VPR [M] [S + j]的[I] = VR [J]。
       }



解决方案

System.arrayCopy 很可能是最快的方法来复制一个数组,但它不会使深层副本

这还不能做你的第二个问题更为复杂的例子。

I'm aware that a common performance refactoring is to replace simple for's by System.arraycopy.

I want to ask about:

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

  2. 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];
       }
    

解决方案

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.

这篇关于多维数组高效System.arraycopy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆