需要更快的阵列复制 [英] Need of a faster array copy

查看:63
本文介绍了需要更快的阵列复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

稍作阅读后,我发现在Java中复制数组的方式有所不同。对于我的应用程序,我有一个递归的节点树,每个节点包含一个2d板阵列(8x8)。

After doing a bit of reading, I discovered that there are some differences in the ways you can copy arrays in java. For my application I have a recursive tree of nodes, each containing a 2d board array (8x8).

通过探查器测试,我能想到的最好的方法是java.util.Arrays.copyOf(array)方法,该方法使用本机System.arraycopy。

Through profiler testing, the best thing I could come up with is the java.util.Arrays.copyOf(array) method, which uses the native System.arraycopy.

即使这样,我还是要花费80%的时间来创建新数组。如果有人对如何加快速度有任何想法,我将不胜感激。也许使用64项数组而不是8x8数组会更快。

Even with this, I am spending 80% of my time creating new arrays. If anyone has any ideas on how to speed this up I'd appreciate it. Perhaps going to a 64 item array rather than an 8x8 would be faster. I'll test this shortly.

推荐答案

我最近在这方面进行了调查(请参阅我对自己问题的回答在有没有办法创建原始数组没有初始化?,它可能被命名为为什么Array.copyOf这么慢或为什么Java这么慢,甚至还向RF发送了RFE。主要思想是Java花费太多时间进行无用的数组初始化。这是关于Arrays.copyOf可能更快的方法。

I've recently done an investigation in this regard (see my answer to my own question at Is there any way to create a primitive array without initialization?, it could have been named "Why Array.copyOf is so slow" or "Why Java is so slow") and even sent an RFE to Oracle. The main idea is that Java spends too much time for useless array initialization. This is about how Arrays.copyOf could have been faster.

这篇关于需要更快的阵列复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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