gpt4 book ai didi

c# - 值类型是否像引用类型一样保留类型指针 + 同步根 + 静态字段?

转载 作者:行者123 更新时间:2023-11-30 12:42:02 27 4
gpt4 key购买 nike

值类型是否像引用类型一样保持类型指针+同步根+静态字段?此问题是以下问题的扩展版本:do-value-types-have-type-objects .任何人都可以澄清:

  • 值类型是否有存储在 CLR 堆中的相关 System.Type 对象?
  • 如果没有关联类型对象,值类型静态字段方法存储在哪里?
  • 值类型是否具有同步根字段(如果没有同步 root block ,值类型是否线程安全)?

最佳答案

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

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

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

无论是 ValueType 还是 ReferenceType,静态字段都存储在称为 "High Frequency Heap" 的特殊堆中每个 AppDomain 都有一个。与“垃圾收集堆”不同,此堆不进行垃圾收集。

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,则它与线程安全无关。

关于c# - 值类型是否像引用类型一样保留类型指针 + 同步根 + 静态字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35185528/

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