Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The last one--<code>realloc(ptr, 0)</code>--comes close. It will free any allocated block and replace it with a minimal allocation (says my Mac OS X 10.5 manpage). Check your local manpage to see what it does on your system.</p> <p>That is, if <code>ptr</code> pointed at a substantial object, you'll get back most of its memory.</p> <hr> <p>The man page on Debian Lenny agrees with <a href="https://stackoverflow.com/questions/750060/is-there-an-alternative-way-to-use-the-free-function-in-c/750068#750068">Mitch</a> and <a href="https://stackoverflow.com/questions/750060/is-there-an-alternative-way-to-use-the-free-function-in-c/750075#750075">Jonathan</a>...does BSD really diverge from Linux on this?</p> <hr> <p>From the offending man page:</p> <blockquote> <p>The realloc() function tries to change the size of the allocation pointed to by ptr to size, and returns ptr. [...] If size is zero and ptr is not NULL, a new, minimum sized object is allocated and the original object is freed.</p> </blockquote> <hr> <p>The linux and solaris man pages are very clean, and the '89 standard: <code>realloc(ptr,0)</code> works like <code>free(ptr)</code>. The Mac OS manpage above, and the standard as quoted by Jonathan are less clear but seems to leave room to break the equivalence.</p> <p>I've been wondering <em>why</em> the difference: the "act like free" interpretation seems very natural to me. Both of the implementations I have access to include <em>some</em> environment variable driven tunablity, but the BSD version accepts many more options Some examples:</p> <blockquote> <pre><code> MallocGuardEdges If set, add a guard page before and after each large block. </code></pre> </blockquote> <pre><code> MallocDoNotProtectPrelude If set, do not add a guard page before large blocks, even if the MallocGuardEdges envi- ronment variable is set. MallocDoNotProtectPostlude If set, do not add a guard page after large blocks, even if the MallocGuardEdges envi- ronment variable is set. </code></pre> <p>and</p> <blockquote> <pre><code> MallocPreScribble If set, fill memory that has been allocated with 0xaa bytes. This increases the likeli- hood that a program making assumptions about the contents of freshly allocated memory will fail. </code></pre> </blockquote> <pre><code> MallocScribble If set, fill memory that has been deallo- cated with 0x55 bytes. This increases the likelihood that a program will fail due to accessing memory that is no longer allo- cated. </code></pre> <p>Possibly the "minimum sized object" is nothing (i.e. equivalent to <code>free</code>) in the normal modes, but <em>something</em> with some of the guards in place. Take that for what it's worth.</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. 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