Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We've had pretty good luck by writing our own malloc and free functions. In production, they just call the standard malloc and free, but in debug, they can do whatever you want. We also have a simple base class that does nothing but override the new and delete operators to use these functions, then any class you write can simply inherit from that class. If you have a ton of code, it may be a big job to replace calls to malloc and free to the new malloc and free (don't forget realloc!), but in the long run it's very helpful.</p> <p>In Steve Maguire's book <a href="http://www.microsoft.com/mspress/books/1024.aspx" rel="nofollow noreferrer">Writing Solid Code</a> (highly recommended), there are examples of debug stuff that you can do in these routines, like:</p> <ul> <li>Keep track of allocations to find leaks</li> <li>Allocate more memory than necessary and put markers at the beginning and end of memory -- during the free routine, you can ensure these markers are still there</li> <li>memset the memory with a marker on allocation (to find usage of uninitialized memory) and on free (to find usage of free'd memory)</li> </ul> <p>Another good idea is to <em>never</em> use things like <code>strcpy</code>, <code>strcat</code>, or <code>sprintf</code> -- always use <code>strncpy</code>, <code>strncat</code>, and <code>snprintf</code>. We've written our own versions of these as well, to make sure we don't write off the end of a buffer, and these have caught lots of problems too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload