File:  [MW Coherent from dump] / coherent / a / usr / man / ALL / calloc
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



calloc()                 General Function                calloc()




Allocate dynamic memory

cchhaarr *ccaalllloocc(_c_o_u_n_t, _s_i_z_e) uunnssiiggnneedd _c_o_u_n_t, _s_i_z_e;

calloc is one of a set  of routines that helps manage a program's
arena.  ccaalllloocc  calls mmaalllloocc  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 free.

calloc  returns  the  address  of  the  chunk of  memory  it  has
allocated, or NULL if it could not allocate memory.

***** Example *****

This example  attempts to  ccaalllloocc a  small portion of  memory; it
then reallocates it to demonstrate rreeaalllloocc.


#include <stdio.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);
}


***** See Also *****

arena, free(),  general functions, malloc(),  memok(), realloc(),
setbuf()



COHERENT Lexicon                                           Page 1



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.