是否值类型保留类型的指针+同步根+静态字段,如引用类型? [英] Does a value type keep Type pointer + Sync root + Static fields like a reference type?

查看:123
本文介绍了是否值类型保留类型的指针+同步根+静态字段,如引用类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否值类型保持的类型的指针+同步根+静态字段像一个引用类型?这个问题是下列之一的扩展版本: DO值类型,有型-objects 。任何人都可以澄清:




  • 请值类型有存储在CLR堆中一个相关的System.Type对象

  • 其中值类型的静态字段方法的,如果没有相关类型的对象存储?

  • 请值类型已经同步根域(是值类型,线程安全的,如果没有同步<击>根块为他们)?


解决方案

不要值类型都存储在一个相关的类对象在CLR堆?




没有,没有。结构不具有报头与它相关联并且没有类型信息与它一起存储。如果你问有关的System.Type ,是类型的元数据将在堆。但它不会被创建的前期。




在哪里,如果在线程栈中没有相关的
类对象的值类型的静态字段存储?




无论值类型和引用类型的,静态字段存储在一个名为的高频堆,你必须每个AppDomain之一。不同的是回收堆垃圾,这堆是不是垃圾收集。




每一个静态变量存储在堆中,无论$的b $ b检查的引用类型或值类型内声明。只有
共一个插槽​​不管如何创建多个实例。 (有
不必成为一个时隙存在
虽然创建的所有实例。)请注意,这堆是从普通垃圾
回收堆独立的 - 它被称为高频堆,这里面的每个应用程序域
有一个




以上内容由乔恩斯基特



报价

不要值类型已经同步根域(是值类型,线程安全的,如果没有同步根他们的)?




不知道你问这里。如果你的意思的SyncBlock,而不是同步根,它没有任何关系线程安全。


Does a value type keep Type pointer + Sync root + Static fields like a reference type? This question is an extended version of the following one: do-value-types-have-type-objects. Can anyone clarify:

  • Do value types have a related System.Type-object stored in CLR heap?
  • Where value type static fields and methods are stored if there is no associated type object?
  • Do value types have sync root field (are value types thread safe if there is no sync root block for them)?

解决方案

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

No, There isn't. Structs don't have header associated with it and no type information is stored along with it. If you ask about the System.Type, yes the Type metadata will be in heap. But it won't be created upfront.

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

Irrespective of ValueType or ReferenceType, static fields are stored in special heap called "High Frequency Heap" which you have one per AppDomain. Unlike the "Garbage Collected Heap", this heap is not garbage collected.

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)?

Not sure what you're asking here. If you mean SyncBlock instead of Sync-Root, it has nothing to do with thread safety.

这篇关于是否值类型保留类型的指针+同步根+静态字段,如引用类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆