4 ms·
Not defending it for general use, but dynamic linking can be very useful for test and instrumentation. Also sometimes for solvers and simulators, but that's eve
by OnlyOneCannolo 5y ago
Not defending it for general use, but dynamic linking can be very useful for test and instrumentation. Also sometimes for solvers and simulators, but that's even more niche.
- Banana699 5y agoCan you please elaborate? Why would the ability to change the library version at runtime be useful for testing? and what aspect of this is useful for simulators and solvers?
- dathinab 5y agoYou compile a version of the dependency which intentionally behaves different (e.g. introduces random network errors, random file parsing errors, etc.) and "inject" it into a otherwise functional setup to check if all other parts including error reporting and similar work. There are always other ways to archive this but using (abusing?) the dynamic linking is often the simpler way to set it up. > and what aspect of this is useful for simulators and solvers? Duno, but some programs allow plugin in different implementations of the same performance critical functionality so that you can distribute a binary version and then only re-compile that part with platform specific optimizations. If that is what the author is referring to I would argue today there are better ways to do it. But it's still working out either way and can be much easier to setup/maintain in some cases. (And probably falls into the "shared libraries as extension system" category Linus excluded from his commentary.)
- OnlyOneCannolo 5y agoThat's part of it, which I agree falls under the excluded category. I was thinking more about code generation and program modification. Curious what the better way to swap implementations would be?
- OnlyOneCannolo 5y agoI should clarify - it's at the start of runtime when the library is initially loaded. Not afterwards. You'd have to restart the program to swap a library. For testing and simulation, it's a way to mock dependencies. You get to test the otherwise exact binary you'll deploy. And you can inject tracing and logging. Solver installations tend to be long-lived, but require customizations, upgrades, and fixes over time. Dynamic linking lets you do that without going through the pain of reinstalling it every time. Also with solvers you're likely to see unconventional stuff for performance or even just due to age.
- ofrzeta 5y ago> ... when the library is initially loaded. Not afterwards. You'd have to restart the program to swap a library. When you close the library with dlclose() you can swap it during runtime, too.
- duped 5y agoDependency injection is useful for mock testing in C/C++ although there are more programmatic ways to do it for the latter