“标称存储分配”是什么意思?在原始数据类型分配大小的上下文中?

发布于 2024-11-27 06:54:16 字数 180 浏览 1 评论 0原文

查看此表描述了 VB 中的数据类型< /a>.

其中一列标记为“标称存储分配”。这意味着什么?为什么这里要用“名义”这个词呢?

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 技术交流群。

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

发布评论

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

评论(2

毁梦 2024-12-04 06:54:16

我相信,在这种情况下,“标称”是指这些数据类型中包含的实际数据占用的字节数,不包括 CLR 用于跟踪值的任何存储,例如,当值类型装箱时发生的堆分配。

编辑

在阅读链接的文章时,我注意到以下部分:

内存消耗

当您声明基本数据类型时,假设其内存消耗与其标称存储分配相同是不安全的。这是出于以下考虑:

存储分配。公共语言运行时可以根据应用程序执行所在平台的当前特征来分配存储。如果内存几乎已满,它可能会将声明的元素尽可能紧密地打包在一起。在其他情况下,它可能会将其内存地址与自然硬件边界对齐以优化性能。

平台宽度。 64 位平台上的存储分配与 32 位平台上的存储分配不同。

所以基本上这就是说,每个值类型的总存储空间是名义存储空间+任何可用于在字边界对齐值的填充+可能的堆分配-同样,由运行时自行决定。

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:

Memory Consumption

When you declare an elementary data type, it is not safe to assume that its memory consumption is the same as its nominal storage allocation. This is due to the following considerations:

Storage Assignment. The common language runtime can assign storage based on the current characteristics of the platform on which your application is executing. If memory is nearly full, it might pack your declared elements as closely together as possible. In other cases it might align their memory addresses to natural hardware boundaries to optimize performance.

Platform Width. Storage assignment on a 64-bit platform is different from assignment on a 32-bit platform.

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.

时光暖心i 2024-12-04 06:54:16

“名义”是指运行时可以自由地为给定变量分配尽可能多的空间。虽然 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.

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