How a reference in C# is implemented internally? [closed]
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)
精彩评论