.\" Copyright (c) 1980 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\" @(#)malloc.3 6.4 (Berkeley) %G%
malloc, free, realloc, calloc, alloca \- memory allocator
.B char *realloc(ptr, size)
.B char *calloc(nelem, elsize)
.B unsigned nelem, elsize;
provide a general-purpose memory allocation package.
returns a pointer to a block of at least
bytes beginning on a word boundary.
is a pointer to a block previously allocated by
this space is made available for further allocation,
but its contents are left undisturbed.
Needless to say, grave disorder will result if the space assigned by
is overrun or if some random number is handed to
maintains multiple lists of free blocks according to size,
allocating space from the appropriate list.
to get more memory from the system when there is no
suitable space already free.
changes the size of the block pointed to by
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.
simply returns the value of
called with an argument of
In order to be compatible with older versions,
points to a block freed since the last call of
were previously used to attempt storage compaction.
This procedure is no longer recommended.
allocates space for an array of
The space is initialized to zeros.
bytes of space in the stack frame of the caller.
This temporary space is automatically freed on
Each of the allocation routines returns a pointer
to space suitably aligned (after possible pointer coercion)
for storage of any type of object.
or larger, the memory returned will be page-aligned.
return a null pointer (0) if there is no available memory or if the arena
has been detectably corrupted by storing outside the bounds of a block.
may be recompiled to check the arena very stringently on every transaction;
those sites with a source code license may check the source code to see
returns 0, the block pointed to by
The current implementation of
does not always fail gracefully when system
memory limits are approached.
It may fail to allocate memory when larger free blocks could be broken
up, or when limits are exceeded because the size is rounded up.
It is optimized for sizes that are powers of two.
is machine dependent; its use is discouraged.