Click here to Skip to main content
15,918,808 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralVisual Studio.net 2003 Pin
(Steven Hicks)n+121-Nov-03 7:57
(Steven Hicks)n+121-Nov-03 7:57 
GeneralRe: Visual Studio.net 2003 Pin
Mike Dimmick21-Nov-03 13:15
Mike Dimmick21-Nov-03 13:15 
QuestionPrinting the contents of a CListCtrl ? Pin
Brian van der Beek21-Nov-03 5:27
Brian van der Beek21-Nov-03 5:27 
AnswerRe: Printing the contents of a CListCtrl ? Pin
Roger Allen21-Nov-03 6:29
Roger Allen21-Nov-03 6:29 
GeneralRe: Printing the contents of a CListCtrl ? Pin
Brian van der Beek23-Nov-03 21:25
Brian van der Beek23-Nov-03 21:25 
GeneralUsing SetCheck in a dialog app. menu Pin
cercis21-Nov-03 4:46
cercis21-Nov-03 4:46 
GeneralRe: Using SetCheck in a dialog app. menu Pin
RChin21-Nov-03 5:18
RChin21-Nov-03 5:18 
GeneralMemory Managers with C, C++ and MFC Pin
Patje21-Nov-03 3:58
Patje21-Nov-03 3:58 
Managing memory (leaks and overwrites) was quite easy when were using plain C.
We just had to define malloc(size) and free(ptr) to point to our own OurMalloc(size) and OurFree(ptr).
From that moment on we could add wonderful stuff to OurMalloc and OurFree like pooling memory chunks, checking for overwrites (using red zones before and after the allocated areas), checking for leaks, even storing the call stack at the moment of the malloc so a decent memory leak could be reported at the end of the program.

Then came C++. This was a bit more difficult since we now also had to reroute the new and delete operator. But after some investigation we found out how to implement those operators to forward their calls again to OurMalloc and OurFree.

Then came MFC. MFC (we use the most recent Visual Studio .Net) does not like the redirection of the global new and delete. You get all kinds of nice linking errors and warnings and even if you succeed in compiling it, you're guaranteed to have run-time crashes because your own new and delete is used instead of the MFC ones --> BIG PROBLEM.

So we end up with our old plain C code using our own advanced memory manager, and the C++ code (using MFC) that uses the MFC memory manager.

That's not the only problem: once in a while, our defines of malloc and free causes problems if an external include file (of the compiler or a 3rd party) has a method free defined in a class and it is called in an inline method. Then our own OurFree is called instead of the class's free method --> BIG PROBLEM.

I tried to look up methods of using custom memory allocators but only find methods that can only be used in a debug version (e.g. malloc_dbg, _CrtSetAllocHook, DEBUG_NEW, ...) and no method that works in release executables as well.

What I want to obtain is the following:
  • Having a memory manager that performs memory pooling (in debug and release builds), checks for overwrites, leaks and reports the call stack for leaks (in debug builds). External tools like Purify often give rubbish output so that's not an option to check for leaks.
  • Having a memory manager that can be used for plain C calls (malloc,free) and C++ new and delete 'calls' with and without MFC.

    Is there a good article on how to add a custom memory manager to C/C++/MFC?
    Are there any good commercial or freeware or open source memory managers that perform these tasks and can be used with plain C, C++ and MFC?

    Thanks for your input.





    Enjoy life, this is not a rehearsal !!!

  • QuestionHow to get rid of the "Help" button in a property sheet in wizard mode? Pin
    Salvador Dali21-Nov-03 3:13
    Salvador Dali21-Nov-03 3:13 
    AnswerRe: How to get rid of the "Help" button in a property sheet in wizard mode? Pin
    Michael P Butler21-Nov-03 3:34
    Michael P Butler21-Nov-03 3:34 
    GeneralCFileException Pin
    ns21-Nov-03 2:39
    ns21-Nov-03 2:39 
    GeneralRe: CFileException Pin
    Mike Dimmick21-Nov-03 3:02
    Mike Dimmick21-Nov-03 3:02 
    GeneralRe: CFileException Pin
    ns21-Nov-03 3:18
    ns21-Nov-03 3:18 
    QuestionResize a listctrl? Pin
    Zizilamoroso21-Nov-03 1:02
    Zizilamoroso21-Nov-03 1:02 
    AnswerRe: Resize a listctrl? Pin
    Zizilamoroso21-Nov-03 1:07
    Zizilamoroso21-Nov-03 1:07 
    GeneralDoes anyone knows this Pin
    Shehzad Salim21-Nov-03 0:54
    Shehzad Salim21-Nov-03 0:54 
    GeneralRe: Does anyone knows this Pin
    RChin21-Nov-03 1:48
    RChin21-Nov-03 1:48 
    GeneralRe: Does anyone knows this Pin
    Michael P Butler21-Nov-03 2:49
    Michael P Butler21-Nov-03 2:49 
    Generalisdigit(); Pin
    WREY21-Nov-03 0:54
    WREY21-Nov-03 0:54 
    GeneralRe: isdigit(); Pin
    Taka Muraoka21-Nov-03 0:59
    Taka Muraoka21-Nov-03 0:59 
    GeneralRe: isdigit(); Pin
    WREY21-Nov-03 1:11
    WREY21-Nov-03 1:11 
    GeneralRe: isdigit(); Pin
    Taka Muraoka21-Nov-03 1:12
    Taka Muraoka21-Nov-03 1:12 
    GeneralRe: isdigit(); Pin
    WREY21-Nov-03 1:22
    WREY21-Nov-03 1:22 
    GeneralRe: isdigit(); Pin
    Michael Dunn21-Nov-03 4:23
    sitebuilderMichael Dunn21-Nov-03 4:23 
    GeneralCSV file into Excel Sheet Pin
    KKR21-Nov-03 0:42
    KKR21-Nov-03 0:42 

    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.