I am trying to get my head in C # in the initial / late binding.
Non-different methods are always bound to start. Virtual methods are always bound to be delayed: the compiler inserts additional code to solve the actual method to bind execution time, and if the type checks for security, subtype polymorphism uses late-bond.
Calling methods using reflection are an example of late bondage. We write the code to get it in opposition to the compiler. (For example, calling Com Components.)
VB.NET supports built-in late bonding when the option is strictly closed. The object is delayed when it is assigned to the declared declaration of an object. The VB compiler incorporates the code to bind the execution time correctly and capture invalid calls. C # does not support this feature.
Am I going in the right direction?
Are the representatives calling and calling a method through an interface reference? Is it the starting or interval binding?
The initial bound only means that the target method is found at the time of compilation, and The code is made which will call it. Its virtual or not (which means that call time is an extra step to find it) is irrelevant. If the method does not exist, the compiler will fail to compile the code.
Being late-bound means that the goal method is seen at the time of running. To see it often, the lexical name of the method is used, if not the method, the bang.
Most script languages use late binding, and compiled languages use initial binding.
C # (before version 4) does not bind late; Although they can use the reflection API to do this, it compiles the API code that looks at function names by digging through assemblies at run time. VB may be late due to the closure of the option.
Binding usually affects performance, since late binding needs to be seen in runtime, it usually means that the call method is slower than the initial bound method call.
For a normal function, the compiler can create its numeric position in memory, then the function is called when it can generate a command to call the function at this address.
If there are any virtual ways for an object, the compiler will generate a v-table. This is essentially an array that contains addresses of virtual methods. Each object that contains a virtual method will be a hidden member generated by the compiler, which is the address of the v-table. When a virtual function is called, then the compiler will do the job that the position is in the appropriate table in the V-Table. After this, the objects will be able to see in V-Table and in this situation the code will be called for the virtual method.
Therefore, there is a lookup for a virtual function, it is quite optimized, so it will be very fast in run-time.
Initial binding
- Where the compiler says the function will be on time compilation.
- The compiler can guarantee a quick (before running program code) function that will be present and callable on runtime.
- The compiler guarantees that the function takes the correct number of arguments and that they are of the right type. It also checks that the return value is of the right type.
late binding
- Lookup will take longer because it does not have a simple offset count, usually a comparison of text can be made.
- The target function may not exist.
- The target function can not accept the arguments given to it, and the wrong type of return value can be.
- With some implementation, the goal method can actually change in run-time, so lookup can execute a different function. I think that this happens in Ruby language, you can define a new method on an object, while the program is running.
Comments
Post a Comment