Click here to Skip to main content
15,914,071 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMemory Mapping Pin
22-Feb-01 6:57
suss22-Feb-01 6:57 
GeneralRe: Memory Mapping Pin
l a u r e n22-Feb-01 9:22
l a u r e n22-Feb-01 9:22 
GeneralMixing DEBUG and RELEASE DLLs. Pin
Chris Meech22-Feb-01 5:55
Chris Meech22-Feb-01 5:55 
GeneralRe: Mixing DEBUG and RELEASE DLLs. Pin
l a u r e n22-Feb-01 6:13
l a u r e n22-Feb-01 6:13 
GeneralRe: Mixing DEBUG and RELEASE DLLs. Pin
Chris Meech22-Feb-01 6:33
Chris Meech22-Feb-01 6:33 
GeneralRe: Mixing DEBUG and RELEASE DLLs. Pin
Erik Funkenbusch22-Feb-01 12:29
Erik Funkenbusch22-Feb-01 12:29 
GeneralRe: Mixing DEBUG and RELEASE DLLs. Pin
Chris Meech23-Feb-01 7:01
Chris Meech23-Feb-01 7:01 
GeneralRe: Mixing DEBUG and RELEASE DLLs. Pin
26-Feb-01 8:14
suss26-Feb-01 8:14 
Hi Chris,

If you look under the hood, you'll see that for Release MFC/MSVCRT that
new calls malloc() and delete calls free().

For Debug MFC and MSVCRT all calls to malloc() and free() actually go to malloc_dbg()
and free_dbg(). Since malloc and malloc_dbg() are exported functions they are only accessible via the jump table in the IAT of your DLL that is linked to MFC42uD.DLL (or MFC42D.DLL if you are MBCS). The import library will indicate that it wants MFC42uD.DLL or MFC42.DLL and will not resolve to the incorrect DLL (ie if it wants the release on it won't link against the debug one).

So that being the case it is pretty hard to call the release malloc() if you know you linked against the debug malloc(). If you want to try, put a breakpoint on a call to
new/malloc or free/delete and drop into assembly level and walk the calls, you can
tell very quickly if you ended up in the release or debug dll (for a start the source code only comes up in the debug dll as there is no debug info in the release dll to main to the release CRT source code that MFC ship.).

You should also note that many big name tools, such as Purify, will report that your program is using both MSVCRTD.DLL and MSVCRT.DLL at the same time. Why do they do this?
Your program is debug, so that explains MSVCRTD.DLL. Their program (the one that has
been injected into your program to inspect it) is almost certainly release code(*),
which explains MSVCRT.DLL. So why would they do that? The reason is that:-
a) Microsoft forbids the redistribution of DEBUG dlls.
b) The performance gains of using the release DLLs and the knowledge that an ASSERT
(that may just be a warning, not a genuine problem) can't come up.
As long as their program never mixes its calls up and always calls its MSVCRT.DLL
then it will be OK. So there are occasions when it is OK, but as other posters here
have noted, usually it is NOT ok.

It sounds like the 3rd party dll may be incorrectly assuming any memory that is passed to it to manage is always 'release mode' (for want of a better term) memory. In that case you are out of luck.

The memory management for DEBUG is pretty straightforward. The source code is in the MFC directory and implements its own linked list manager with a lot of overhead to
allow you to track it. It grabs larger chunks using HeapAlloc on a private heap.

The Release memory management consists of a small block heap, implemented in a way
that will not map in any way to the DEBUG memory management. For larger blocks
(greater than the value returned by sbh_get_threshold(), typically 0x03f8) the release
manager goes to HeapAlloc() in a private heap. Consult sbheap.c and winheap.c for
more details.

Hope this is some use. Any chance of naming the vendor/dll?

Stephen Kellett

GeneralRe: Mixing DEBUG and RELEASE DLLs. Pin
Erik Funkenbusch26-Feb-01 12:31
Erik Funkenbusch26-Feb-01 12:31 
GeneralRe: Mixing DEBUG and RELEASE DLLs. Pin
27-Feb-01 5:47
suss27-Feb-01 5:47 
GeneralSearching a custom Database Pin
jerry0davis22-Feb-01 5:48
jerry0davis22-Feb-01 5:48 
GeneralRe: Searching a custom Database Pin
l a u r e n22-Feb-01 5:57
l a u r e n22-Feb-01 5:57 
Generaldelete and delete [] what is the difference Pin
22-Feb-01 5:35
suss22-Feb-01 5:35 
GeneralRe: delete and delete [] what is the difference Pin
Michael Dunn22-Feb-01 6:39
sitebuilderMichael Dunn22-Feb-01 6:39 
GeneralRe: delete and delete [] what is the difference Pin
Etienne Danvoye22-Feb-01 7:19
Etienne Danvoye22-Feb-01 7:19 
GeneralRe: delete and delete [] what is the difference Pin
Erik Funkenbusch22-Feb-01 12:47
Erik Funkenbusch22-Feb-01 12:47 
GeneralRe: delete and delete [] what is the difference Pin
Ryan Park23-Feb-01 14:56
Ryan Park23-Feb-01 14:56 
Generalbad arrays .. Pin
Travis D. Mathison22-Feb-01 4:06
Travis D. Mathison22-Feb-01 4:06 
GeneralRe: bad arrays .. Pin
Chris Losinger22-Feb-01 4:49
professionalChris Losinger22-Feb-01 4:49 
GeneralRe: bad arrays .. Pin
l a u r e n22-Feb-01 6:03
l a u r e n22-Feb-01 6:03 
GeneralRe: bad arrays .. Pin
Julien22-Feb-01 15:24
Julien22-Feb-01 15:24 
GeneralRe: bad arrays .. Pin
Travis D. Mathison22-Feb-01 16:27
Travis D. Mathison22-Feb-01 16:27 
QuestionDatabase programming?? Pin
22-Feb-01 3:37
suss22-Feb-01 3:37 
GeneralListBox problem ... Pin
Hadi Rezaee22-Feb-01 0:56
Hadi Rezaee22-Feb-01 0:56 
GeneralListCtrl Scrolling Pin
banrio21-Feb-01 23:55
banrio21-Feb-01 23:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.