Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ () — Coherent 3.1.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought


calloc()                 General Function                calloc()




Allocate dynamic memory

char *calloc(count, size) unsigned count, size;

calloc is one of a set  of routines that helps manage a program's
arena.  calloc  calls malloc  to obtain  a block large  enough to
contain count  items of size 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  calloc a  small portion of  memory; it
then reallocates it to demonstrate realloc.


#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


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026