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

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

问题描述

我知道一个常见的性能重构是用 System.arraycopy 替换简单的 for.

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

我想问:

  1. system.arraycopy 什么时候开始有意义(考虑到它是一个本地方法调用).复制小东西是不是说,<32有什么优势?

  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?

这是我的印象,还是不能简单地(有效地)使用 arraycopy 复制这样的循环:

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 可能是复制数组最快的方法,但它不会进行深度复制.

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天全站免登陆