Dilemma with using value types with `new` operator in C#

后端 未结 5 1300
后悔当初
后悔当初 2020-12-29 10:42

When operator new() is used with reference type, space for the instance is allocated on the heap and reference variable itself is placed on the stack. Besides t

5条回答
  •  悲&欢浪女
    2020-12-29 11:28

    From developer point of view you have no knowledge where it is allocated. For example, an exotic device with CLR which has no idea of the stack -> everthing goes on the heap. Even if you consider the desktop CLR, in some cases JITer can move variables from the stack to the heap.

    More info.

提交回复
热议问题