Jump to content

Overriding Malloc?


Josh
 Share

Recommended Posts

I want to do some memory testing, but every approach I read about doesn't work.

  • Application verifier uses an enormous amount of memory and makes testing impossible.
  • Including afx.h doesn't work because I've got tons of libraries I use that include windows.h.
  • I can't figure out how to override malloc / free because I just get a ton of errors.

 

Is there another way to do this?

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I have been able to improve memory testing with this code:

#ifdef DEBUG
_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF|
_CRTDBG_ALLOC_MEM_DF |
_CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode(_CRT_ERROR,
_CRTDBG_MODE_WNDW);
_CrtSetReportMode(_CRT_ASSERT,
_CRTDBG_MODE_WNDW);
#endif

 

Very very slow but it seems to catch memory overwrites I intentionally added for testing.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Yes, unfortunately Valgrind is only available for Linux and Unices. It is a fantastic tool and super easy to use. I often make it my first line of debugging info for C++ because so many bugs also cause memory leaks.

 

Probably the only real drawbacks are the slow runtime (unavoidable) and large amount of debug output.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...