Re: DLL pass vector by value crash
On Thu, 27 Aug 2009 01:41:04 -0700 (PDT), Goran <goran.pusic@gmail.com>
wrote:
I mean, what is the
purpose of having separate modules, when they have to share compiler,
(probably) compiler options, and CRT/MFC versions?
Note that those conditions are the same as those implied by using a static
library. If I'm thinking about creating a static library, I always consider
using a DLL instead:
1. DLLs provide well-defined order of initialization of globals WRT other
modules (other DLLs and EXE). (On the downside, there are those pesky
DllMain restrictions to consider.)
2. DLLs offer easier function/data visibility control. By default,
everything is private to the DLL, and only what is explicitly exported is
exposed. Also, you don't have to worry about things like using anonymous
namespaces to protect classes that are intended to be private to the
module, something I expect a lot of static libraries fail to do.
3. No inter-module optimization is possible. (This is probably more often a
slight disadvantage, but if you are writing, say, a synchronization
primitive, it is necessary.)
4. With care, DLLs can often be updated independently of the rest of the
program.
5. Potentially less code and disk space bloat, though this is less and less
a concern every day.
To the extent they're not used by DLLs, static libraries do have the
advantage of being free of DllMain restrictions, and they don't suffer from
the template static data problem.
--
Doug Harrison
Visual C++ MVP