小编Joã*_*aas的帖子

JavaScript数组如何存储在内存中

因此,我在考虑如何在JavaScript中将数组存储在内存中。

我已经读过JavaScript数组如何在物理内存中表示?,但找不到答案。

我在想的更多是关于阵列单元的内存位置。例如,在C语言中,定义数组时需要定义数组的大小。这样,C定义了整个内存块,并且它可以查找每个单元的确切位置。

例如:

int array[10]; // C knows the memory location of the 1st item of the array

array[3] = 1   // C can do that, because it can calculate the location 
               // of array[3] by doing &array + 3 * (int size)
Run Code Online (Sandbox Code Playgroud)

在JS中,可以在将内存分配给其他对象之后增加数组的大小,这意味着JS不适用于“块”类型的数组。

但是,如果数组不是单个内存块,那么JS如何计算每个单元在哪里?JS数组遵循链接列表类型的结构吗?

javascript memory arrays

6
推荐指数
1
解决办法
404
查看次数

标签 统计

arrays ×1

javascript ×1

memory ×1