为什么不能阵列调整大小? [英] Why can't arrays be resized?

查看:182
本文介绍了为什么不能阵列调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是为什么阵列,原始或以其他方式,就不能调整大小动态的原因是什么?

What is the reason why arrays, primitive or otherwise, cannot be re-sized dynamically?

我知道你可以使用的ArrayList ,但它背后的实现仍是初始大小(我认为这是50默认情况下),以及数组当它超过50,一个新的阵列将创建包含这些元素。

I know you can use ArrayList, but the implementation behind it is still an array of initial size (I think it's 50 by default), and when it exceeds 50, a new array will be created to contain those elements.

所以,我想了解一个数组,使其unresizable的系统规范。

So, I am trying to understand the system specification of an array that make it unresizable.

推荐答案

这是一个有效的问题,答案有做电脑是如何工作的。

This is a valid question, and the answer has to do with how computers actually work.

当您创建一个数组,使用 INT []数组=新INT [5] 例如,计算机储量连续五个空格在内存中包含的数据该阵列。然而,在存储器的空间后,可以马上用于存储其它信息。如果阵列是要在以后调整,其他信息将不得不为了其他地方移动的阵列来获得更大。这是一个很大,我们不希望处理的洗牌,让计算机设计师禁止阵列调整,使事情变得更简单。

When you create an array, using int[] array = new int[5] for instance, the computer reserves five consecutive spaces in memory for the data to be contained in that array. However, the spaces in memory after that can be used right away to store other information. If the array were to be resized later on, that other information would have to be moved somewhere else in order for the array to get bigger. That's a lot of shuffling that we don't want to deal with, so computer architects disallow array resizing to make things simpler.

这篇关于为什么不能阵列调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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