JavaScript 数组实际上是链表吗? [英] Are JavaScript arrays actually linked lists?
问题描述
我是 Javascript 的新手,注意到您不需要指定数组的大小,并且经常看到人们一次动态地创建一个元素的数组.在其他语言中,这将是一个巨大的性能问题,因为随着数组大小的增加,您将不断需要为数组重新分配内存.
I'm new to Javascript, and notice that you don't need to specify an array's size and often see people dynamically creating arrays one element at time. This would be a huge performance problem in other languages as you would constantly need to reallocate memory for the array as it increases in size.
这在 JavaScript 中不是问题吗?如果是这样,那么是否有可用的列表结构?
Is this not a problem in JavaScript? If so, then is there a list structure available?
推荐答案
这很可能取决于您使用的 JavaScript 引擎.
It most likely depends on what JavaScript engine you use.
Internet Explorer 混合使用稀疏数组和密集数组来实现这一目标.这里解释了一些更血腥的细节:http://blogs.msdn.com/b/jscript/archive/2008/04/08/performance-optimization-of-arrays-part-ii.aspx.
Internet Explorer uses a mix of sparse arrays and dense arrays to make that work. Some of the more gory details are explained here: http://blogs.msdn.com/b/jscript/archive/2008/04/08/performance-optimization-of-arrays-part-ii.aspx.
这篇关于JavaScript 数组实际上是链表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!