Annotation of coherent/a/usr/man/ALL/calloc, revision 1.1.1.1

1.1       root        1: 
                      2: 
                      3: calloc()                 General Function                calloc()
                      4: 
                      5: 
                      6: 
                      7: 
                      8: Allocate dynamic memory
                      9: 
                     10: cchhaarr *ccaalllloocc(_c_o_u_n_t, _s_i_z_e) uunnssiiggnneedd _c_o_u_n_t, _s_i_z_e;
                     11: 
                     12: calloc is one of a set  of routines that helps manage a program's
                     13: arena.  ccaalllloocc  calls mmaalllloocc  to obtain  a block large  enough to
                     14: contain _c_o_u_n_t  items of _s_i_z_e bytes each;  it then initializes the
                     15: block to  zeroes.  When this memory is no  longer needed, you can
                     16: return it to the free pool by using the function free.
                     17: 
                     18: calloc  returns  the  address  of  the  chunk of  memory  it  has
                     19: allocated, or NULL if it could not allocate memory.
                     20: 
                     21: ***** Example *****
                     22: 
                     23: This example  attempts to  ccaalllloocc a  small portion of  memory; it
                     24: then reallocates it to demonstrate rreeaalllloocc.
                     25: 
                     26: 
                     27: #include <stdio.h>
                     28: 
                     29: main()
                     30: {
                     31:         register char *ptr, *ptr2;
                     32:         extern char *calloc(), *realloc();
                     33:         unsigned count, size;
                     34: 
                     35: 
                     36: 
                     37:         count = 4;
                     38:         size = sizeof(char *);
                     39: 
                     40: 
                     41: 
                     42:         if ((ptr = calloc(count, size)) != NULL)
                     43:                 printf("%u blocks of size %u calloced\n",
                     44:                         count, size);
                     45:         else
                     46:                 printf("Insuff. memory for %u blocks of size %u\n",
                     47:                      count, size);
                     48: 
                     49: 
                     50: 
                     51:         if ((ptr2 = realloc(ptr,(count*size) + 1)) != NULL)
                     52:                 printf("1 block of size %u realloced\n",
                     53:                         (count*size)+1);
                     54: }
                     55: 
                     56: 
                     57: ***** See Also *****
                     58: 
                     59: arena, free(),  general functions, malloc(),  memok(), realloc(),
                     60: setbuf()
                     61: 
                     62: 
                     63: 
                     64: COHERENT Lexicon                                           Page 1
                     65: 
                     66: 

unix.superglobalmegacorp.com

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