gpt4 book ai didi

.net - stsfld 与 stfld

转载 作者:行者123 更新时间:2023-12-02 07:46:00 28 4
gpt4 key购买 nike

查看 stfld 和 stsfld il 操作码之间的区别,stfld 具有空引用检查,而 stsfld 没有。为什么是这样?是因为静态字段在高频堆上,所以它们没有被垃圾收集吗?

http://msdn.microsoft.com/library/system.reflection.emit.opcodes.stfld.aspx

The stack transitional behavior, in sequential order, is:

  1. An object reference or pointer is pushed onto the stack.
  2. A value is pushed onto the stack.
  3. The value and the object reference/pointer are popped from the stack; the value of field in the object is replaced with the supplied value.

The stfld instruction replaces the value of a field of an object (type O) or via a pointer (type native int, &, or *) with a given value. Field is a metadata token that refers to a field member reference. The stfld instruction can have a prefix of either or both of Unaligned and Volatile.

NullReferenceException is thrown if the object reference or pointer is a null reference and the field isn't static.

MissingFieldException is thrown if field is not found in the metadata. This is typically checked when the Microsoft Intermediate Language (MSIL) instruction is converted to native code, not at runtime.

最佳答案

静态成员从不 有一个目标实例。如果有参数(在方法上),arg0 指的是第一个参数,而不是目标实例(aka this)。由于没有目标实例,空检查是没有意义的:没有什么可以取消引用。

关于.net - stsfld 与 stfld,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6999970/

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