开发者

How a reference in C# is implemented internally? [closed]

开发者 https://www.devze.com 2023-03-03 19:52 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_开发百科 Closed 11 years ago.

Just wondering how a reference in C# is implemented internally?

alias? const pointer?

still need an elaborate answer on this.

thanks.


In current implementations, a reference is just a pointer.

To your program, there is no difference at all between a reference and a pointer, everything that is special about references is handled by the compiler and the garbage collector.

What's relevant to know, really, is that a reference doesn't take up more space than a pointer, and there is no extra step needed to use a reference. A reference is not a pointer to a pointer, or an identity that has to be looked up to get to the actual data.

The .NET memory management doesn't use reference counting, like some other frameworks, so there is no counter that has to be maintained when creating or removing references.


References:

  • .NET Type Internals - From a Microsoft CLR Perspective
  • Heap, Stack, Reference Types and Value Types in .NET
  • Exploring the CLR (Types)
0

精彩评论

暂无评论...
验证码 换一张
取 消