gpt4 book ai didi

Java : large array design

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:36 25 4
gpt4 key购买 nike

当我阅读此链接时 Java Criticism .在大阵列部分。有两点我不明白:

Java also lacks true multidimensional arrays (contiguously allocated single blocks of memory accessed by a single indirection), which limits performance for scientific and technical computing

在C中,我知道多维数组只是元素的连续内存。所以,正如上面的部分,Java 中的每一行都是一个对象,多行就像多对象一样,它们在内存中不是连续的,对吧?

Java has been criticized for not supporting arrays of more than 231 - 1 (about 2.1 billion) elements ... Arrays must be indexed by int values... An attempt to access an array component with a long index value results in a compile-time error

这是否意味着,如果我们可以通过长整数访问数组组件,则数组大小可以更大?在那种情况下,数组的这个限制大小仍然是 long 的大小,对吧?

谢谢:)

最佳答案

... each row in Java is an object, and multi rows just like multi objects, and they're not contiguous in memory, right ?

没错。 Java 多维数组是数组的数组,每个数组表示为一个单独的对象。

Does this mean, if we can access an array component by long integer, the array size can be bigger ?

没有。 Java 数组的最大大小为 2^31 - 1 个元素。

JLS 在 JLS 10.4 中这样说:

"Arrays must be indexed by int values; short, byte, or char values may also be used as index values because they are subjected to unary numeric promotion (§5.6.1) and become int values.

An attempt to access an array component with a long index value results in a compile-time error."


简而言之,您链接到的页面正确指出 Java 不适合需要使用非常大数组的应用程序。 (可以解决这些限制,但是如果不将底层数组表示形式包装为对象,您就无法干净地完成它。这会影响性能,并且意味着您不能使用 [...] 索引语法。)

关于Java : large array design,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12756108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com