Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ malloc(3C) — sys5 — Apollo

Media Vault

Software Library

Restoration Projects

Artifacts Sought



MALLOC(3C)      DOMAIN/IX Reference Manual (SYS5)      MALLOC(3C)



NAME
     malloc, free, realloc, calloc - main memory allocator

USAGE
     char *malloc (size)
     unsigned size;

     void free (ptr)
     char *ptr;

     char *realloc (ptr, size)
     char *ptr;
     unsigned size;

     char *calloc (nelem, elsize)
     unsigned nelem, elsize;

DESCRIPTION
     Malloc and free provide a simple memory allocation package.
     Malloc returns a pointer to a block of at least size bytes
     aligned for any use.

     The argument to free is a pointer to a block previously
     allocated by malloc; free makes this space available for
     further allocation, but leaves its contents undisturbed.

     Unexpected results will occur if the space assigned by mal-
     loc is overrun, or if an incorrect ptr is handed to free.

     Malloc allocates the first contiguous reach of size bytes of
     free space that it finds, in a circular search from the last
     space allocated or freed.  Malloc connects adjacent free
     blocks as it searches.  It calls sbrk (see brk(2)) to get
     more memory from the system when there is not sufficient
     space already free.

     Realloc changes the size of the block that ptr points to, to
     size bytes, and returns a pointer to the block.  The con-
     tents will be unchanged, up to the lesser of the new and old
     sizes.  If no free block of size bytes is available in the
     storage area, then realloc will ask malloc to enlarge the
     area by size bytes and then move the data to the new space.

     Realloc also works if ptr points to a block freed since the
     last call of malloc, realloc, or calloc.  Thus, sequences of
     free, mallooc, and realloc can use the searching strategy of
     malloc to perform storage compaction.

     Calloc allocates space for an array of nelem elements of
     size elsize.  The space is initialized to zeros.





Printed 5/10/85                                          MALLOC-1





MALLOC(3C)      DOMAIN/IX Reference Manual (SYS5)      MALLOC(3C)



     Each of the allocation routines returns a pointer to space
     suitably aligned (after possible pointer coercion) for
     storage of any type of object.

NOTES
     Search time increases when many objects have been allocated.
     That is, if your program allocates space but never frees it,
     then each successive allocation takes longer.

DIAGNOSTICS
     Malloc, realloc, and calloc return a NULL pointer if there
     is no available memory or if the area has been detectably
     corrupted by storing data beyond the bounds of a block.
     When this happens, the block pointed to by ptr may be des-
     troyed.

RELATED INFORMATION
     brk(2)





































MALLOC-2                                          Printed 5/10/85



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