V8 如何存储像 5 这样的整数?

编程入门 行业动态 更新时间:2024-10-13 16:23:15
本文介绍了V8 如何存储像 5 这样的整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

V8 如何在内存中存储整数?

How does V8 store integers in memory?

例如整数 5?

我知道它将它存储在堆中,但它究竟是如何存储它的?诸如元数据和实际值本身之类的东西.在存储之前是否有一个常量添加到 int 中?

I know it stores it the heap, but how exactly does it store it? Things like metadata and the actual value itself. Is there a constant added to the int before storing it?

推荐答案

V8 使用指针标记方案来区分小整数和堆对象指针.5 将存储为 Smi 类型,这不是 V8 中分配的堆.

V8 uses a pointer tagging scheme to distinguish small integers and heap object pointers. 5 would be stored as a Smi type, which is not heap allocated in V8.

您可以查看 源代码 供 Smi 类了解更多信息.

You can check out the source code for the Smi class to learn more.

在 32 位平台上,Smis 是一个 31 位有符号整数,底位设置为 0.在 64 位平台上,Smis 是一个 32 位有符号整数、31 位填充 0 和一个 0 代表底位.指向堆对象的指针的底部位设置为 1,因此 V8 可以在没有额外元数据的情况下区分指针和 Smis.

On 32-bit platforms, Smis are a 31 bit signed int with a 0 set for the bottom bit. On 64-bit platforms, Smis are a 32 bit signed int, 31 bits of 0 padding and a 0 for the bottom bit. Pointers to heap objects have a 1 set for the bottom bit so that V8 can tell the difference between pointers and Smis without extra metadata.

更多推荐

V8 如何存储像 5 这样的整数?

本文发布于:2023-10-18 15:05:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504579.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!