> I have a question on how to build a universal DLL(Dynamic
> Linking Library)or Lib(static library), which could be
> used both in Debug and Release verisons. As i know,
> edition of the application which invokes the library must
> be the same with DLL. The application in Debug only works
> with the DLL in Debug, otherwise the Release is the same.
It isn't necessary to match apps and dlls but it's a Good Thing To Do.
If it will never happen a situation where one side allocate memory and
the other free it, and if none of the sides relies on memory appart
from what it gets via function arguments then there shouldn't be any
problems (if I'm wrong somebody please correct me).
To put it simply if your dll does malloc/new then it must free/delete.
If it is really necessary to pass buffer management to the other side
then there should be a function from buffer creator's side available
to buffer receiver for buffer deallocation.
In another words if there is a function in your dll:
char* CreateNewBuffer(void);
ther there should be as well:
void DeleteBufferCreatedInThisDll(char*);
Tony Nassar - 03 Jan 2004 15:39 GMT
I'm not sure this is correct. If you're using VS 6.0, then there is a
settings for each DLL and EXE called something like "Link statically" or
"Link dynamically", i.e., "link this module statically with the C runtime
library" or "link this module with the stub library, and load the DLL
version of the C runtime library at runtime." If you build all your modules
with the latter, then there will be only one memory manager (and only one
heap) at runtime, and a DLL *does not* have to free what it created.
> To put it simply if your dll does malloc/new then it must free/delete
Mihajlo Cvetanovic - 04 Jan 2004 16:33 GMT
True, but sometimes a programmer starts playing with compiler/linker
options, and finds out (or worse it doesn't find out) about new "bugs"
never seen before. This is the safe way, or "best programming
practice". Or in biblical terms: "I'm Alfa and Omega, your Constructor
and Destructor!" ;-)
> I'm not sure this is correct. If you're using VS 6.0, then there is a
> settings for each DLL and EXE called something like "Link statically" or
[quoted text clipped - 5 lines]
>
>>To put it simply if your dll does malloc/new then it must free/delete