Search code examples
clate-bindingdynamic-loading

what are similarities and differences between dynamic loading and late binding?


From wikipedia:

Dynamic loading is a mechanism by which a computer program can, at run time, load a library (or other binary) into memory, retrieve the addresses of functions and variables contained in the library, execute those functions or access those variables, and unload the library from memory.

Late binding is a computer programming mechanism in which the method being called upon an object is looked up by name at run-time.


In my opinion,

A similarity is they are both mechanisms in which methods are looked up at run-time.

A difference is dynamic loading does not need to use a linker after loading the library at run-time but late binding always need a linker.

I'm not sure if I am correct, especially the difference part. I would like to learn more from your analysis.


Solution

  • Late binding, much like overcommit, is a hack to squeeze out some extra benefit (performance / memory allowance) at the expense of correctness and possible late catastrophic failure.

    Without late binding, dynamic loading of modules will succeed only if all symbols needed for relocation can be resolved at load time, and you get a meaningful error from which you can recover if they can't be resolved. With late binding, dynamic loading virtually always "succeeds", then can crash your program later when the dynamic loaded module tries to reference a symbol that can't be resolved.