[英]Behind Windows x64's 44-bit virtual memory address limit
http://www.alex-ionescu.com/?p=50 . 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. 作者通过单链列表示例解释了为什么Windows x64仅支持44位虚拟内存地址。
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. 首先要做出的牺牲是将序列号的空间减少到9位而不是16位,减少列表可以达到的最大序列号。 This still only left 39 bits for the pointer — a mediocre improvement over 32 bits. 这仍然只剩下39位用于指针-比32位有中等改进。 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. 通过将结构分配时强制为16字节对齐,可以再赢得4位,因为现在始终可以将最低位假定为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." “通过在分配时强制结构对齐16字节,可以再赢得4位,因为现在始终可以将最低位假定为0。” means? 手段?
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. 您可以看到,对于所有16的倍数,最后四位始终为零。 So, instead of storing these bits you can leave them out and add them back in when it's time to use the pointer. 因此,除了存储这些位之外,您还可以将其保留下来,并在需要使用指针时将其重新添加回去。
For a 2^N-byte aligned pointer, its address is always divisible by 2^N - which means that lower N bits are always zero. 对于2 ^ N字节的对齐指针,其地址始终可被2 ^ N整除-这意味着低N位始终为零。 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
- ie a number with low N bits set. 其中mask是(1 << N) - 1
即设置了低N位的数字。
This trick is often used to save space in low-level code (payload can be GC flags, type tag, etc.) 此技巧通常用于在低级代码中节省空间(有效载荷可以是GC标志,类型标记等)
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. 当然,应注意不要将数字解引用为指针而不进行解码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.