C# properties: How are they instantiated?
Posted
by Pedery
on Stack Overflow
See other posts from Stack Overflow
or by Pedery
Published on 2009-06-17T05:38:00Z
Indexed on
2010/06/14
14:02 UTC
Read the original article
Hit count: 176
Hi!
This might be a pretty straightforward question, but I'm trying to understand some of the internal workings of the compilation.
Very simply put, imagine an arbitrary object being instantiated. This object is then allocated on the heap. The object has a property of type PointF (which is value type), with a get and a set method.
Imagine the get and the set method containing a few calculations for doing their work. How and where (stack/heap) and when is this code instantiated?
This is the background for this question:
I'm writing get and set methods for an object and these methods need to be accessed very frequently. The get and set code in itself is rather massive so I feared that in a worst case scenario the methods would be instantiated as an object or a value type with all internal code for every access of the property. On the other hand the code is probably instantiated when the main object is created and the CPU is simply told to jmp to the property code start. Anyway, this is what I want to have clarified.
© Stack Overflow or respective owner