boolean
是否在内存中存储为 32 位整数? null
值怎么样?
在书中Speaking Javascript ,
它指的是一个类型标签,用于指示存储在内存中的值的类型。例如Object
类型的类型标签是 000。什么是类型标签?
如何找到值类型的 type 标记,例如 boolean
或 string
?
最佳答案
来自 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 源代码。但如果我没记错的话,true
和 false
表示为根指针。
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/