xref: /csrg-svn/lib/libc/stdlib/malloc.3 (revision 61180)
1*61180Sbostic.\" Copyright (c) 1980, 1991, 1993
2*61180Sbostic.\"	The Regents of the University of California.  All rights reserved.
320400Smckusick.\"
450309Sbostic.\" This code is derived from software contributed to Berkeley by
550309Sbostic.\" the American National Standards Committee X3, on Information
650309Sbostic.\" Processing Systems.
750309Sbostic.\"
848349Scael.\" %sccs.include.redist.man%
920400Smckusick.\"
10*61180Sbostic.\"     @(#)malloc.3	8.1 (Berkeley) 06/04/93
1148349Scael.\"
1248349Scael.Dd
1348349Scael.Dt MALLOC 3
1448349Scael.Os BSD 4
1548349Scael.Sh NAME
1648349Scael.Nm malloc ,
1748349Scael.Nd general memory allocation function
1848349Scael.Sh SYNOPSIS
1948349Scael.Fd #include <stdlib.h>
2048349Scael.Ft void *
2148349Scael.Fn malloc "size_t size"
2248349Scael.Sh DESCRIPTION
2348349ScaelThe
2448349Scael.Fn malloc
2548349Scaelfunction allocates uninitialized space for an object whose
2648349Scaelsize is specified by
2748349Scael.Fa size .
2848349ScaelThe
2948349Scael.Fn malloc
3048349Scaelfunction maintains multiple lists of free blocks according to size, allocating
3148349Scaelspace from the appropriate list.
3248349Scael.Pp
3348349ScaelThe allocated space is
3448349Scaelsuitably aligned (after possible pointer
3548349Scaelcoercion) for storage of any type of object. If the space is of
3648349Scael.Em pagesize
3728178Skarelsor larger, the memory returned will be page-aligned.
3848349Scael.Sh RETURN VALUES
3948349ScaelThe
4048349Scael.Fn malloc
4148349Scaelfunction returns
4248349Scaela pointer to the allocated space if successful; otherwise
4348349Scaela null pointer is returned.
4448349Scael.Sh SEE ALSO
4548349Scael.Xr brk 2 ,
4648897Ssellgren.Xr pagesize 2 ,
4748349Scael.Xr free 3 ,
4848349Scael.Xr calloc 3 ,
4948349Scael.Xr alloca 3 ,
5048349Scael.Xr realloc 3 ,
5148349Scael.Xr memory 3
5248349Scael.Sh STANDARDS
5348349ScaelThe
5448349Scael.Fn malloc
5548349Scaelfunction conforms to
5648349Scael.St -ansiC .
5748349Scael.Sh BUGS
5828178SkarelsThe current implementation of
5948349Scael.Xr malloc
6028178Skarelsdoes not always fail gracefully when system
6128178Skarelsmemory limits are approached.
6228178SkarelsIt may fail to allocate memory when larger free blocks could be broken
6328178Skarelsup, or when limits are exceeded because the size is rounded up.
6428178SkarelsIt is optimized for sizes that are powers of two.
65