'\"macro stdmacro
.if n .pH g3c.malloc @(#)malloc	40.17 of 10/27/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} malloc 3C "C Programming Language Utilities" "\&"
.if \nX=1 .ds x} malloc 3C "C Programming Language Utilities"
.if \nX=2 .ds x} malloc 3C "" "\&"
.if \nX=3 .ds x} malloc "" "" "\&"
.TH \*(x}
.SH NAME
\f4malloc\f1, \f4free\f1, \f4realloc\f1, \f4calloc\f1, \f4memalign\f1, \f4valloc\f1, \- memory allocator
.SH SYNOPSIS
\f4#include <stdlib.h>\f1
.PP
\f4void \(**malloc (size_t size);\f1
.PP
\f4void free (void \(**ptr);\f1
.PP
\f4void \(**realloc (void \(**ptr, size_t size);\f1
.PP
\f4void \(**calloc (size_t nelem, size_t elsize);\f1
.PP
\f4void \(**memalign(size_t alignment, size_t size);\f1
.PP
\f4void \(**valloc(size_t size);\f1
.SH DESCRIPTION
\f4malloc\fP
and
\f4free\fP
provide a simple general-purpose memory allocation package.
\f4malloc\fP
returns a pointer to a block of at least
.I size\^
bytes suitably aligned for any use.
.PP
The argument to
\f4free\fP
is a pointer to a block previously allocated by
\f4malloc\fP,
\f4calloc\fP
or \f4realloc\fP.
After
\f4free\fP
is performed this space is made available for further allocation.
If \f2ptr\f1 is a \f4NULL\fP pointer,
no action occurs.
.PP
Undefined results will occur if the space
assigned by
\f4malloc\fP
is overrun or if some random number is handed to
\f4free\fP.
.PP
\f4realloc\fP
changes the size of the block pointed to by
.I ptr\^
to
.I size\^
bytes and returns a pointer to the (possibly moved)
block.
The contents will be unchanged up to the
lesser of the new and old sizes.
If \f2ptr\f1 is \f4NULL\fP, \f4realloc\fP behaves like \f4malloc\fP for
the specified size.
If \f2size\f1 is zero and \f2ptr\f1 is not a null pointer,
the object pointed to is freed.
.PP
\f4calloc\fP
allocates space for
an array of
.I nelem\^
elements of size
.IR elsize .
The space is initialized to zeros.
.PP
\f4memalign\f1 allocates
\f2size\fP
bytes on a specified alignment boundary,
and returns a pointer to the allocated block.
The value of the returned address is guaranteed to be
an even multiple of
\f2alignment\fP.
Note: the value of
.I alignment
must be a power of two, and must be greater than
or equal to the size of a word.
.PP
\f4valloc(size)\f1
is equivalent to
\f4memalign(sysconf(_SC_PAGESIZE),size)\f1.
.PP
Each of the allocation routines returns a pointer
to space suitably aligned (after possible pointer coercion)
for storage of any type of object.
.PP
\f4malloc\fP, \f4realloc\fP, \f4calloc\fP, \f4memalign\f1, and \f4valloc\f1
will fail if there is not enough available memory.
.SH "SEE ALSO"
\f4malloc\fP(3X).
.SH DIAGNOSTICS
If there is no available memory, 
\f4malloc\fP,
\f4realloc\fP,
\f4memalign\fP,
\f4valloc\fP,
and
\f4calloc\fP
return a null pointer.
When \f4realloc\fP returns \f4NULL\fP, the
block pointed to by \f2ptr\f1 is left intact.
If \f2size\f1, \f2nelem\f1\^, or \f2elsize\f1 is 0, a unique pointer
to the arena is returned.
.\"	@(#)malloc.3c	6.3 of 10/20/83
.Ee
