Java:一维数组在内存中总是连续的吗? [英] Java: are 1-d arrays always contiguous in memory?

查看:61
本文介绍了Java:一维数组在内存中总是连续的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过的许多关于这个主题的书籍/文章,以及我使用Unsafe"编写的一个小程序,都表明 Java 中的一维数组在内存中总是连续的.那么它是由 JLS 规定的还是一个实现约定?询问此问题以确认此指示.

Many books/articles I've read on this topic, as well as a small program I wrote using 'Unsafe', indicate that 1-d arrays in Java are always contiguous in memory. So is it dictated by JLS or is it an implementation convention? The question is asked to confirm this indication.

推荐答案

不,JVM 规范没有任何这样的保证:http://docs.oracle.com/javase/specs/jvms/se5.0/html/Concepts.doc.html#16446

No, the JVM specification does not have any such guarantees: http://docs.oracle.com/javase/specs/jvms/se5.0/html/Concepts.doc.html#16446

在实践中可能是这种情况,但您也无法保证字的大小.

In practice it is probably the case but you also have no guarantee about the word size.

Unsafe 不是标准的 Java 类,所以如果您的程序使用它,那么它无论如何都不可移植...

Unsafe is not a standard Java class, so if your program uses this, then it is not portable anyway...

这篇关于Java:一维数组在内存中总是连续的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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