If I have an application that compiles as .exe and I want to use the library, I can either statically link this library from the .lib file, or dynamically link this library from the .dll file.
Each associated module (i.e., each .exe or .dll) will be associated with a C or C ++ runtime implementation. Runtimes themselves are a library that can be statically or dynamically linked to various thread configurations.
Speaking of statically linked dlls, do you describe a setup in which a .exe application dynamically links to a .dll library, and does this library statically link to a runtime? I will assume that this is what you mean.
It is also worth noting that each module (.exe or .dll) has its own scope for statics, i.e. global statics in .exe will not be the same instance as global statics with the same name in .dll.
Therefore, in the general case, it cannot be assumed that lines of code running inside different modules use the same implementation of the runtime; moreover, they will not use the same instance of any static state.
Therefore, when working with objects or pointers that cross the boundaries of modules, certain rules must be followed. Allocations and releases must occur in the same module for any given address. Otherwise, the heaps will not match and the behavior will not be determined.
COM solves this problem with reference counting; objects are deleted when the reference count reaches zero. This is a generic pattern used to solve a consistent location problem.
There may be other problems, for example, windows defines certain actions, for example, how allocation failures are handled for each thread, and not for each module. This means that the code executed in module A in the thread configured by module B can also work in an unexpected way.
morechilli May 30 '12 at 16:37 2012-05-30 16:37
source share