Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In a comment to the question, I wrote that <code>calloc()</code> allows better memory alignment for platforms where it matters. I haven't been able to find anything to support that (yet). I am pretty sure it was a feature of the VMS/VAXC compiler, but source for that is scarce.</p> <hr> <p>However, I did find that <code>calloc()</code> and <code>alloc()</code> appeared at the same time, with the release of Unix V6 in May 1975. In V5, released 11 months earlier, neither function is present; the kernel and runtime library (and assembler and C compiler) were written in assembly.</p> <p>In the V6 release, <a href="http://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/iolib/calloc.c" rel="nofollow">calloc is implemented</a> as the four line source code module:</p> <pre><code>calloc(n, s) { return(alloc(n*s)); } </code></pre> <p><code>calloc()</code> does not clear the allocated memory; see <a href="http://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/source/iolib/alloc.c" rel="nofollow"><code>alloc()</code></a>, and there was no <code>man</code> page for <code>calloc()</code> in V6; however the <a href="http://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/man/man3/alloc.3" rel="nofollow">man page for <code>alloc()</code></a>:</p> <blockquote> <p>DESCRIPTION<br> <strong>Alloc</strong> and <strong>free</strong> provide a simple general-purpose core management package. <em>Alloc</em> is given a size in bytes; it returns a pointer to an area at least that size which is even and hence can hold an object of any type. The argument to <em>free</em> is a pointer to an area previously allocated by <em>alloc;</em> this space is made available for further allocation.</p> <p>Needless to say, grave disorder will result if the space assigned by <em>alloc</em> is overrun or if some random number is handed to <em>free.</em></p> <p>The routine uses a first-fit algorithm which coalesces blocks being freed with other blocks already free. It calls <em>sbrk</em> (see <em>"break (II))"</em> to get more core from the system when there is no suitable space already free.</p> <p>DIAGNOSTICS<br> Returns <strong>-1</strong> if there is no available core.</p> <p>BUGS<br> Allocated memory contains garbage instead of being cleared.</p> </blockquote> <p>Not even <code>NULL</code> is returned in the case of memory exhaustion!</p> <p><code>calloc()</code> first formally appears in UNIX V7, January 1979, along with several other <a href="http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/man/man3/malloc.3" rel="nofollow">improvements</a>:</p> <ul> <li><code>calloc()</code> clears the memory returned.</li> <li><code>alloc()</code> was renamed to <code>malloc()</code></li> <li><code>realloc()</code> appeared</li> <li>in the case of memory exhaustion or a heap error, the functions "return a null pointer (0)"</li> </ul>
    singulars
    1. This table or related slice is empty.
    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.
 

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