javascript - V8中,null、undefined、boolean等基本类型在内存中是如何存储的?

标签 javascript v8 javascript-engine

boolean 是否在内存中存储为 32 位整数? null 值怎么样?

在书中Speaking Javascript , 它指的是一个类型标签,用于指示存储在内存中的值的类型。例如Object 类型的类型标签是 000。什么是类型标签?

如何找到值类型的 type 标记,例如 booleanstring

最佳答案

来自 Andy Wingo 的 blog post关于主题:

Initially, all JavaScript implementations used tagged pointers to represent JS values. This is a old trick that comes from the observation that allocated memory takes up at least 4 or 8 bytes, and are aligned in such a way that the least significant bit or three will be zero.

所以类型标签允许统一存储所有值。所有值都占用一个机器字(32/64 位),并且根据标签(这是最低有效位),它们被解释为指向对象的指针或某些整数/ bool 值/等,具体取决于标签。

is boolean stored as a 32-byte integer in js memory?

bool 值也占一个字。要获得更具体的答案,我需要查看 v8 源代码。但如果我没记错的话,truefalse 表示为根指针。

how to get the type tag of a value type(boolean,undefined,string, number);

无法通过 JavaScript 执行此操作。它是内部实现细节。

关于javascript - V8中,null、undefined、boolean等基本类型在内存中是如何存储的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32733314/

相关文章:

c99 - 将 Google V8 嵌入 ANSI C 应用程序 - 从哪里开始?

safari - webkit 中的 safari javascript 引擎

javascript - 除了 V8 之外,是否有任何带有 JavaScript 引擎的 node.js 平台的端口或替代实现?

javascript - Angular 应用程序不显示 $scope 数据

javascript - 如果 jquery 列表有类则隐藏文本框

javascript - 数据加载时 knockout 验证停止计算错误

javascript - 一组多边形的外部包络

javascript - google d8 (v8 shell),每次按回车键时输出 "undefined"

javascript - 使用 'with' 关键字在 Javascript 中进行范围解析

javascript - Node : How to enable non strict or ECMASCRIPT3 in V8 engine?