981377660LMT / ts

ts学习
6 stars 1 forks source link

js 存储 #394

Open 981377660LMT opened 9 months ago

981377660LMT commented 9 months ago

“JavaScript values in V8 are represented as objects and allocated on the V8 heap, no matter if they are objects, arrays, numbers or strings. This allows us to represent any value as a pointer to an object.” “V8 中的 JavaScript 值被表示为对象并在 V8 堆上分配,无论它们是对象、数组、数字还是字符串。这允许我们将任何值表示为指向对象的指针。

981377660LMT commented 9 months ago

https://www.zhenghao.io/posts/javascript-memory

981377660LMT commented 9 months ago

网上有大量资源声称,在 JavaScript 中,原语值是在堆栈上分配的,而对象是在堆上分配的。这个想法是错误的,至少在我见过的大多数JavaScript引擎中,这不是语言的实现方式。我正在输入这篇文章,以便我可以链接到它并在将来节省一些时间。

981377660LMT commented 9 months ago

All JavaScript values are allocated on the heap accessed by pointers no matter if they are objects, arrays, strings or numbers (except for small integers i.e. smi in V8 due to pointer tagging). 所有 JavaScript 值都分配在指针访问的堆上,无论它们是对象、数组、字符串还是数字(小整数除外,即 smi 在 V8 中由于指针标记)。

The stack only stores temporary, function-local and small variables (mostly pointers) and that's largely unrelated to JavaScript types. 堆栈只存储临时的、函数局部的和小变量(主要是指针),这在很大程度上与 JavaScript 类型无关。