数组是在Java虚拟顺序内存数据结构?或物理顺序? [英] Is array in java virtually sequential memory data structure? or physically sequential?

查看:362
本文介绍了数组是在Java虚拟顺序内存数据结构?或物理顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到什么是基本的Java数组和列表数据结构(如ArrayList)之间的差异,并找到文章或Q&安培; A像这样(的 List和Array 之间的差异)。许多文章包括链接点Java原始'阵'是'的顺序记忆。在这一点上,是什么顺序是什么呢?这是在物理内存中连续真的?或连续虚拟内存?我的猜测是在虚拟内存中的顺序,因为操作系统和一般的应用程序(JVM)分配的物理内存不关心具体的内存分配。但我不知道确切的答案。

I try to find what is difference between primitive java 'array' and 'List' data structure (like ArrayList), and find articles or Q&A like this (Difference between List and Array). Many articles including that link point that java primitive 'array' is 'sequential memory'. In this point, what is sequential exactly? is this really sequential in physical memory? or sequential in virtual memory? My guess is sequential in virtual memory, because OS assigns physical memory in general and application(JVM) doesn't care about specific memory allocation. But I do not know exact answer.

推荐答案

一个Java数组是在物理内存中的虚拟内存的顺序不一定。

A Java array is sequential in virtual memory not necessarily in physical memory.

一个用户空间应用程序(如JVM)拥有超过构成的虚拟地址空间的物理页面是否在内存中连续的没有发言权。而事实上,它没有,甚至知道这个典型的现代操作系统的方式。这是所有从机器的虚拟内存的硬件和(用户空间)指令集架构的用户空间应用程序隐藏的。

A user-space application (such as a JVM) has no say over whether the physical pages that make up its virtual address space are contiguous in memory. And in fact, it has no way of even knowing this in typical modern operating systems. This is all hidden from a user-space application by the machine's virtual memory hardware and (user-space) instruction set architecture.

纵观JVM规范是不是要上物理内存的问题启发。那简直是不相关的。

Looking at the JVM spec is not going to be instructive on the physical memory issue. It is simply not relevant.

和它不会出现的任务的,数组是在虚拟内存中连续的。然而,参与非连续虚拟内存再presentations会导致昂贵的数组操作,所以你不可能找到一个主流的JVM的做到这一点。)

And it doesn't appear to mandate that arrays are contiguous in virtual memory. However, representations that involved non-contiguous virtual memory would lead to expensive array operations, so you are unlikely to find a mainstream JVM that does this.)

参考文献:

Java虚拟机没有强制要求对象的任何特定的内部结构。

规范的其他部分暗示,物是指这里的班级和阵列两个实例。

Other parts of the spec imply that "objects" refers here to BOTH instances of classes AND arrays.

JVM规格2.4了解阵列谈判,但它并没有提及他们是如何重新在内存presented。

JVM Spec 2.4 talks about arrays, but it doesn't mention how they are represented in memory.

阵列和的ArrayList S之间的区别是在一个较高的水平。阵列具有固定的大小。的ArrayLists具有可变的大小。但引擎盖下,一个ArrayList是使用(单)阵列...可以重新分配(即替换)如果列表增长得太大实施。

The difference between arrays and ArrayLists are at a higher level. Arrays have a fixed size. ArrayLists have a variable size. But under the hood, an ArrayList is implemented using a (single) array ... which can be reallocated (i.e. replaced) if the list grows too big.

这篇关于数组是在Java虚拟顺序内存数据结构?或物理顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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