Windows x64的44位虚拟内存地址限制背后

发布于 2024-10-09 10:23:29 字数 557 浏览 6 评论 0原文

http://www.alex-ionescu.com/?p=50

我读了上面的帖子。作者以单链表为例解释了为什么Windows x64仅支持44位虚拟内存地址。

struct { // 8 字节头
        乌龙龙深度:16;
        ULONGLONG 序列:9;
        ULONGLONG 下一条:39;
标题8;

要做的第一个牺牲是减少序列的空间 将数字从 16 位改为 9 位,减少最大序列 列表中可以实现的数字。这仍然只留下 39 位 指针 — 与 32 位相比的平庸改进。通过强制 结构体在分配时是 16 字节对齐的,还可以多 4 位 赢了,因为现在可以始终假定底部位为 0。


哦,我不明白。

“通过在分配时强制结构进行 16 字节对齐,可以多赢得 4 位,因为现在可以始终假定底部位为 0。”方法?

http://www.alex-ionescu.com/?p=50.

I read the above post. The author explains why Windows x64 supports only 44-bit virtual memory address with singly linked list example.

struct {  // 8-byte header
        ULONGLONG Depth:16;
        ULONGLONG Sequence:9;
        ULONGLONG NextEntry:39;
} Header8;

The first sacrifice to make was to reduce the space for the sequence
number to 9 bits instead of 16 bits, reducing the maximum sequence
number the list could achieve. This still only left 39 bits for the
pointer — a mediocre improvement over 32 bits. By forcing the
structure to be 16-byte aligned when allocated, 4 more bits could be
won, since the bottom bits could now always be assumed to be 0.


Oh, I can't understand.

What "By forcing the structure to be 16-byte aligned when allocated, 4 more bits could be won, since the bottom bits could now always be assumed to be 0." means?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清欢 2024-10-16 10:23:29
16 is 0010000 in binary

32 is 0100000 in binary

64 is 1000000 in binary

等等

您可以看到,对于所有 16 的倍数的数字,最后四位始终为零。
因此,您可以将它们保留下来,并在需要使用指针时将它们添加回来,而不是存储这些位。

16 is 0010000 in binary

32 is 0100000 in binary

64 is 1000000 in binary

etc

You can see that for all numbers that are multiples of 16, the last four bits are always zero.
So, instead of storing these bits you can leave them out and add them back in when it's time to use the pointer.

挖鼻大婶 2024-10-16 10:23:29

对于 2^N 字节对齐的指针,其地址始终可被 2^N 整除 - 这意味着低 N 位始终为零。您可以在其中存储附加信息:

encode ptr payload = ptr | payload
decode_ptr data = data & ~mask
decode_payload data = data & mask

其中掩码为 (1 << N) - 1 - 即设置了低 N 位的数字。

这个技巧通常用于节省低级代码中的空间(有效负载可以是 GC 标志、类型标记等)。

实际上,您存储的不是指针,而是可以从中提取指针的数字。当然,应注意不要在未解码的情况下将数字作为指针取消引用。

For a 2^N-byte aligned pointer, its address is always divisible by 2^N - which means that lower N bits are always zero. You can store additional information in them:

encode ptr payload = ptr | payload
decode_ptr data = data & ~mask
decode_payload data = data & mask

where mask is (1 << N) - 1 - i.e. a number with low N bits set.

This trick is often used to save space in low-level code (payload can be GC flags, type tag, etc.)

In effect you're not storing a pointer, but a number from which a pointer can be extracted. Of course, care should be taken to not dereference the number as a pointer without decoding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文