加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 值类型是否保持类型指针同步根静态字段如引用类型?

发布时间:2020-12-15 22:26:32 所属栏目:百科 来源:网络整理
导读:值类型是否保持类型指针同步根静态字段如引用类型?这个问题是以下问题的扩展版本: do-value-types-have-type-objects.任何人都可以澄清: 值类型是否有一个存储在CLR堆中的相关System.Type对象? 如果没有关联的类型对象,则存储值类型静态字段和方法? 值
值类型是否保持类型指针同步根静态字段如引用类型?这个问题是以下问题的扩展版本: do-value-types-have-type-objects.任何人都可以澄清:

>值类型是否有一个存储在CLR堆中的相关System.Type对象?
>如果没有关联的类型对象,则存储值类型静态字段和方法?
>值类型是否具有同步根字段(如果没有同步根块,则值类型是否是线程安全的)?

解决方法

Do value types have a related type-object stored in CLR heap?

不,没有.结构没有与之关联的标题,并且没有类型信息与其一起存储.如果询问System.Type,是类型元数据将在堆中.但它不会预先创建.

Where value type static fields are stored if there is no associated
type object in thread stacks?

无论ValueType或ReferenceType如何,静态字段都存储在名为“High Frequency Heap”的特殊堆中,每个AppDomain都有一个.与“Garbage Collected Heap”不同,此堆不是垃圾回收.

Every static variable is stored on the heap,regardless of whether
it’s declared within a reference type or a value type. There is only
one slot in total no matter how many instances are created. (There
don’t need to be any instances created for that one slot to exist
though.) Note that this heap is separate from the normal garbage
collected heap – it’s known as a “high frequency heap”,and there’s
one per application domain.

Above quote by Jon Skeet

Do value types have sync root field (are value types thread safe if there is no sync root for them)?

不知道你在这里问什么.如果你的意思是SyncBlock而不是Sync-Root,它与线程安全无关.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读