“标称存储分配”是什么意思?在原始数据类型分配大小的上下文中?
其中一列标记为“标称存储分配”。这意味着什么?为什么这里要用“名义”这个词呢?
Looking at this table describing the data types in VB.
One of the columns is labeled "Nominal storage allocation". What does this mean? Why is the word "nominal" here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信,在这种情况下,“标称”是指这些数据类型中包含的实际数据占用的字节数,不包括 CLR 用于跟踪值的任何存储,例如,当值类型装箱时发生的堆分配。
编辑
在阅读链接的文章时,我注意到以下部分:
所以基本上这就是说,每个值类型的总存储空间是名义存储空间+任何可用于在字边界对齐值的填充+可能的堆分配-同样,由运行时自行决定。
I believe that in this context, "nominal" means the number of bytes taken up by the actual data contained in these data types, excluding whatever storage the CLR uses to track the values, e.g. the heap allocation that happens when a value type is boxed.
EDIT
On reading the linked article, I noticed the following section:
So basically this is saying that total storage per value type is nominal storage + whatever padding may be used to align the value at a word boundary + possible heap allocation - again, at the discretion of the runtime.
“名义”是指运行时可以自由地为给定变量分配尽可能多的空间。虽然 Short 仅需要两个字节来存储其数据,但运行时可能会为变量分配 4 个字节。例如,32位机的寄存器中存储的short“占用”4个字节。类似地,堆栈可以以相同的方式工作,即在传递短值作为参数时使用 4 字节的堆栈空间,例如,以保持字对齐。当内存在其自然字边界上对齐时,内存访问通常会更快,因此运行时可能会“浪费”空间来对齐内存。在 64 位计算机上,相同的场景可能会分别使用 8 个字节。
"Nominal" refers to the fact that the runtime is free to allocate as much space as makes sense for a given variable. Although a short only needs two bytes to store its data, the runtime may allocate 4 bytes for the variable. For example, a short stored in a register of a 32-bit machine is "taking up" 4 bytes. Similarly, the stack may work the same way in that 4 bytes of stack space are used when passing a short as a parameter, for example, to maintain word alignment. Memory access is generally faster when memory is aligned on their natural word boundaries, so the runtime may "waste" space to align memory. On 64-bit machines, the same scenarios would probably use 8 bytes each.