gpt4 book ai didi

c# - "allocated inline in a structure"对值类型意味着什么?

转载 作者:行者123 更新时间:2023-11-30 17:12:50 25 4
gpt4 key购买 nike

MSDN 上写着“Value types are allocated on the stack or inline.

“内联分配”是否意味着值类型可以在声明后立即分配?假设它在一个堆中声明,那么它在下一个堆槽中分配?

那为什么说“in a structure”呢?

更新

如果“结构”具体指的是“结构”,为什么它没有提到任何关于“类”的内容?作为 Class 中的字段,它不在堆栈上,也不在 struct 中内联(它在 class 中内联)。

最佳答案

它们是内联分配的在结构中,因此作为已经分配给结构的内存的一部分。

参见:

http://msdn.microsoft.com/en-us/library/system.valuetype.aspx

如果您有嵌套值类型,则内部类型将分配在已为包含类型分配的内存中。

struct Inner
{
public int A;
}

struct Outer
{
public Inner I;
public int B;
}

Outer o = new Outer();
o.I = new Inner();

I 的内存是内联分配的,在分配给 Outer 实例的内存中。

关于c# - "allocated inline in a structure"对值类型意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10358496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com