As you may know, there are several steps from C # code to native code:
- Compilation from C # to IL (bytecode)
- JITting from bytecode to native code
C # does not control the allocation time of what you call binding, it depends entirely on JIT. Extracting this, let's see what is in C # control. The bytecode generated by C # must adhere to the ECR CLR standard. If we move on to section 12.1.6.1 of section 1, we will see that the standard defines that the local variable home is in the header of the method. Since method signatures tend to appear at the beginning of a method in a listing, you get the (false) impression that they are bound in advance, which in fact may or may not be.
If you, however, look at compiled native code, the result may differ from platform to platform. Historically, the allocation of space in the processor stack for a local variable is performed using a single processor instruction to change the stack pointer. If you want to make this a variable variable, you will have many instructions, one per variable, which is less efficient. That is why, at least on x86, you will see that the space in the processor stack is allocated in advance.
Andrew Savinykh
source share