LocalDataStoreSlot 类


封装内存槽以存储本地数据。Encapsulates a memory slot to store local data. 此类不能被继承。This class cannot be inherited.

public ref class LocalDataStoreSlot sealed
public sealed class LocalDataStoreSlot
public sealed class LocalDataStoreSlot
type LocalDataStoreSlot = class
type LocalDataStoreSlot = class
Public NotInheritable Class LocalDataStoreSlot


.NET Framework 提供了两种机制,用于将线程本地存储 (TLS) :线程相对静态字段和数据槽。The .NET Framework provides two mechanisms for using thread local storage (TLS): thread-relative static fields, and data slots.

  • 线程相对静态字段是 static Shared Visual Basic) 中用特性标记的字段 (字段 ThreadStaticAttributeThread-relative static fields are static fields (Shared fields in Visual Basic) that are marked with the ThreadStaticAttribute attribute. 它们提供比数据槽更好的性能,并启用编译时类型检查。They provide better performance than data slots, and enable compile-time type checking.

  • 与线程相关的静态字段相比,数据槽速度较慢且更难使用。Data slots are slower and more awkward to use than thread-relative static fields. 此外,数据存储为类型 Object ,因此,在使用数据之前,必须将其强制转换为正确的类型。Also, data is stored as type Object, so you must cast it to the correct type before using it. 但是,当您在编译时的信息不足以分配静态字段时,您可以使用数据槽。However, you can use data slots when you have insufficient information at compile time to allocate static fields.

有关使用 TLS 的详细信息,请参阅 线程本地存储: Thread-Relative 静态字段和数据槽For more information about using TLS, see Thread Local Storage: Thread-Relative Static Fields and Data Slots.

同样,.NET Framework 提供了两种使用上下文本地存储区的机制:上下文相对静态字段和数据槽。Similarly, the .NET Framework provides two mechanisms for using context local storage: context-relative static fields and data slots. 上下文相对静态字段是用特性标记的静态字段 ContextStaticAttributeContext-relative static fields are static fields that are marked with the ContextStaticAttribute attribute. 使用这两种机制之间的利弊类似于使用线程相对静态字段和数据槽之间的权衡。The trade-offs between using these two mechanisms are similar to the tradeoffs between using thread-relative static fields and data slots.

LocalDataStoreSlot 结构用作本地存储内存机制,线程和上下文可分别使用该机制存储特定于线程的数据和特定于上下文的数据。The LocalDataStoreSlot structure serves as a local store memory mechanism that threads and contexts can use to store thread-specific and context-specific data, respectively. 公共语言运行时在创建每个进程时将多槽数据存储数组分配给它。The common language runtime allocates a multi-slot data store array to each process when it is created. 线程或上下文调用各种函数来分配数据存储区中的数据槽,在槽中存储和检索数据值,并在线程或上下文对象过期后释放数据槽以便重用。The thread or context calls various functions to allocate a data slot in the data store, to store and retrieve a data value in the slot, and to free a data slot for reuse after the thread or context object expires.

数据槽对于每个线程或上下文是唯一的;它们的值不在线程或上下文对象之间共享。The data slots are unique per thread or context; their values are not shared between the thread or context objects. 可以按名称或索引号来分配数据槽。Data slots can be allocated by a name or by an index number.

有关存储本地数据的详细信息,请参阅 ThreadContextFor more information about storing local data, see Thread or Context. LocalDataStoreSlot类与、、和等方法一起 Thread.AllocateNamedDataSlot 使用 Context.AllocateNamedDataSlot Thread.GetData Context.GetData ; 它本身并没有您需要使用的任何方法。The LocalDataStoreSlot class is used with methods such as Thread.AllocateNamedDataSlot, Context.AllocateNamedDataSlot, Thread.GetData, and Context.GetData; it does not have any methods of its own that you need to use.



确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)

确保垃圾回收器回收 LocalDataStoreSlot 对象时释放资源并执行其他清理操作。Ensures that resources are freed and other cleanup operations are performed when the garbage collector reclaims the LocalDataStoreSlot object.


作为默认哈希函数。Serves as the default hash function.

(继承自 Object)

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)