Windows x64的44位虚拟内存地址限制背后
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
等等
您可以看到,对于所有 16 的倍数的数字,最后四位始终为零。
因此,您可以将它们保留下来,并在需要使用指针时将它们添加回来,而不是存储这些位。
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.
对于 2^N 字节对齐的指针,其地址始终可被 2^N 整除 - 这意味着低 N 位始终为零。您可以在其中存储附加信息:
其中掩码为
(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:
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.