值类型是否保持类型指针同步根静态字段如引用类型?这个问题是以下问题的扩展版本: 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,它与线程安全无关.