.\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" the American National Standards Committee X3, on Information .\" Processing Systems. .\" .\" %sccs.include.redist.man% .\" .\" @(#)malloc.3 8.1 (Berkeley) 06/04/93 .\" .Dd .Dt MALLOC 3 .Os BSD 4 .Sh NAME .Nm malloc , .Nd general memory allocation function .Sh SYNOPSIS .Fd #include .Ft void * .Fn malloc "size_t size" .Sh DESCRIPTION The .Fn malloc function allocates uninitialized space for an object whose size is specified by .Fa size . The .Fn malloc function maintains multiple lists of free blocks according to size, allocating space from the appropriate list. .Pp The allocated space is suitably aligned (after possible pointer coercion) for storage of any type of object. If the space is of .Em pagesize or larger, the memory returned will be page-aligned. .Sh RETURN VALUES The .Fn malloc function returns a pointer to the allocated space if successful; otherwise a null pointer is returned. .Sh SEE ALSO .Xr brk 2 , .Xr pagesize 2 , .Xr free 3 , .Xr calloc 3 , .Xr alloca 3 , .Xr realloc 3 , .Xr memory 3 .Sh STANDARDS The .Fn malloc function conforms to .St -ansiC . .Sh BUGS The current implementation of .Xr malloc 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.