ccaalllloocc() -- General Function (libc)

Allocate dynamic memory
#iinncclluuddee <ssttddlliibb.hh>
cchhaarr *ccaalllloocc(_c_o_u_n_t, _s_i_z_e)
uunnssiiggnneedd _c_o_u_n_t, _s_i_z_e;

The  function ccaalllloocc()  is one  of a  set of routines  that helps  manage a
program's arena.  ccaalllloocc() calls mmaalllloocc() to obtain a block large enough to
contain _c_o_u_n_t  items of _s_i_z_e bytes  each; it then initializes  the block to
zeroes.  When  this memory is  no longer needed,  you can return  it to the
free pool by using the function ffrreeee().

ccaalllloocc() returns  the address of the  chunk of memory it  has allocated, or
NULL if it could not allocate memory.

_E_x_a_m_p_l_e
This  example attempts  to  ccaalllloocc() a  small  portion of  memory; it  then
reallocates it to demonstrate rreeaalllloocc().

#include <stdio.h>
#include <stdlib.h>

main()
{
    register char *ptr, *ptr2;
    extern char *calloc(), *realloc();
    unsigned count, size;

    count = 4;
    size = sizeof(char *);

    if ((ptr = calloc(count, size)) != NULL)
        printf("%u blocks of size %u calloced\n",
                count, size);
    else
        printf("Insuff. memory for %u blocks of size %u\n",
             count, size);

    if ((ptr2 = realloc(ptr,(count*size) + 1)) != NULL)
        printf("1 block of size %u realloced\n",
            (count*size)+1);
}

_S_e_e _A_l_s_o
aallllooccaa(),  aarreennaa,  ffrreeee(), lliibbcc,  mmaalllloocc(),  mmeemmookk(), rreeaalllloocc(),  sseettbbuuff(),
ssttddlliibb.hh
ANSI Standard, section 7.10.3.1
POSIX Standard, section 8.1

_N_o_t_e_s
The function aallllooccaa() allocates space on the stack.  The space so allocated
does not need to be freed when the function that allocated the space exits.
