Helpers for debugging memory allocation/deallocation

Today, I posted a long question to the cocoa mailing list of the Apple Computer. At that time, I was thinking about 3 different things at the same time, so my question was not quite correct.

By the way, one guy there told me about an environmental variable which helps memory debugging.

  1. MallocScribble : if set, released memory block will be filled with 0x55
  2. MallocPreScribble : if set, newly allocated block will be filled with 0xAA
  3. MallocGuardEdges : It is like MS’s no-men’s-land

For more, please read Memory Usage Performance Guidelines: Enabling the Malloc Debugging Features

4 responses to this post.

  1. Posted by orchistro on August 6, 2008 at 4:56 AM

    Yet another useful information. Thanks. As far as I know, in some(?) MS Windows versions do the same. They fill released memory block with 0xda or something, can’t really place what was the value though. Didn’t know that OSX did these :-)
    By the way, I got here through han9kin’s blog.

    Reply

  2. Posted by jongampark on August 6, 2008 at 8:10 AM

    Hello, orchistro.
    The Windows version of malloc, which is replaced by malloc_debug() when complied under “Debug” type, sets region called, “No Mens’ Land”. It embraces any allocated region with some prolog block and epilog block.
    For the fillers, I assume you mention this.

    “_malloc_dbg allocates the memory block with slightly more space than the requested size. The additional space is used by the debug heap manager to link the debug memory blocks and to provide the application with debug header information and overwrite buffers. When the block is allocated, the user portion of the block is filled with the value 0xCD and each of the overwrite buffers are filled with 0xFD.”

    What is weird about MSDN document is that it doesn’t contain accurate information although it seems to be “accurate” by mentioning details. About 5 years ago, I also confronted the same issue, and found out that what values an allocated memory region is filled was different among libraries to link to. If you look at the VC++ project setting well, you will notice different link option to system libraries, i.e “Single Thread Static Library”, “Single Thread Dynamic Library”, “Multithread Static Library, “.. you know what I mean. So, in my case I depends on the “No Mens’ Land”.

    What was unlucky with the Mac OS X was that the memory allocator on the Mac was very successful to reuse recently released block. So, it is pretty hard to determine if a newly allocated block is actually newly allocated or it is shallow copied. On Windows, more often than not, the address for newly allocated blocks are different from the recent one. So, it is easy to figure that out.

    By the way, I think it is first time for you to visit my blog. Can you introduce yourself? Or at least the address of your blog or web site which says who you are?

    Thank you for visiting my blog!

    Reply

  3. Posted by orchistro on August 10, 2008 at 12:17 AM

    Well, well, well, I’ve just got an email that your comment is waiting for my approval. I, ah.. I am one of colleagues of han9kin’s. His blog led me to this place, which I found very interesting.

    Talking about myself,.. well, how about, I am just a “below-average” programmer in Seoul. Interested in a few stuffs like *NIX, and vim. About three years ago, I was able to, fortunately, manage myself into my current company where I could learn a substantial amount of knwledge on computer science.

    That’s about everything, I guess, I can tell about myself to other people.

    P.S. I don’t plan to create “About me” page on both my blogs, because the blog itself speaks about its host. :-)

    Reply

  4. Posted by orchistro on August 10, 2008 at 12:20 AM

    Ah, I forgot to write,

    Thank you for showing interest about who I am. ;-) Have a nice weekend.

    Reply

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: