为什么是Java System.arraycopy本土? [英] Why is System.arraycopy native in Java?

查看:384
本文介绍了为什么是Java System.arraycopy本土?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很惊讶,System.arraycopy是一个本地方法的Java源代码中看到的。

I was surprised to see in the Java source that System.arraycopy is a native method.

当然的原因是因为它的速度更快。但是,什么招数本土是code能够运用,使得它更快吗?

Of course the reason is because it's faster. But what native tricks is the code able to employ that make it faster?

为什么不只是原来的阵列上环,每个指针复制到新的数组? - 当然这不是缓慢和繁琐

Why not just loop over the original array and copy each pointer to the new array - surely this isn't that slow and cumbersome?

推荐答案

在本地code,它可以用一个做的memcpy /的 memmove与 ,而不是 N 的不同的复制操作。在性能上的差异是显着

In native code, it can be done with a single memcpy / memmove, as opposed to n distinct copy operations. The difference in performance is substantial.

这篇关于为什么是Java System.arraycopy本土?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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