Aren't Dlls the same as static libs??

Started by
3 comments, last by Void 23 years, 11 months ago
Besides the issues of linking and compiling, dlls should be similar to libs since they dlls are mapped to the process calling space and address.. so.. why is it when I write a wrapper around the C debug libs ( the _CrtDumpMemoryLeaks function, to be exact)and place them in dlls and static libraries, the dlls will not be able to catch memory leaks while the static libraries are able to (for the same program).. Is the dlls viewed as its own process by the C debug lib?? ..
Advertisement
All I can think of is that static libraries really are PART of your program. They are basically obj files that you link in, and they''re part of the same module as the program. So they can catch allocation errors and leaks in their module. But a DLL, even if it''s mapped to the program''s memory, is still a seperate module, and really knows nothing about your program, so it can''t catch memory errors..

That''s just a guess though, I''m not sure

------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
my thoughts too..

but since dlls have no exe main but dllmain and it is attached to the main program.. I would think the C debug lib would be able to differentiate..

Man.. I wish things like this are documented somewhere so we don''t have to waste time learning the hard way..
As far as I know, C++ DLLs have the same heap as the main program (i.e., memory you allocate with new()). You can new() something in the DLL and delete() it in the program and vice versa. Same for malloc() and free(), if C DLLs have the same heap as the main program.

DLLs do have a different stack, but I don''t know why anyone would want to track memory allocation on the stack for a game...


- null_pointer
Sabre Multimedia
What''s probably happening is that you''re statically linking the runtime libraries to both the dll and the executable. Debug memory allocations are logged in a _CrtMemState structure located in the CRT library. Because the dll and the executable are linked to separate copies of the CRT library, the allocations are being logged in the executable''s copy of the _CrtMemState structure and the dll is reporting from the dll''s copy of the _CrtMemState structure. So it''s not a problem of multiple heaps, it''s a problem of multiple logging structures.

This topic is closed to new replies.

Advertisement