xref: /csrg-svn/lib/libc/stdlib/malloc.3 (revision 48349)
1*48349Scael.\" Copyright (c) 1980, 1991 Regents of the University of California.
2*48349Scael.\" All rights reserved.
320400Smckusick.\"
4*48349Scael.\" %sccs.include.redist.man%
520400Smckusick.\"
6*48349Scael.\"     @(#)malloc.3	6.5 (Berkeley) 04/19/91
7*48349Scael.\"
8*48349Scael.Dd
9*48349Scael.Dt MALLOC 3
10*48349Scael.Os BSD 4
11*48349Scael.Sh NAME
12*48349Scael.Nm malloc ,
13*48349Scael.Nd general memory allocation function
14*48349Scael.Sh SYNOPSIS
15*48349Scael.Fd #include <stdlib.h>
16*48349Scael.Ft void *
17*48349Scael.Fn malloc "size_t size"
18*48349Scael.Sh DESCRIPTION
19*48349ScaelThe
20*48349Scael.Fn malloc
21*48349Scaelfunction allocates uninitialized space for an object whose
22*48349Scaelsize is specified by
23*48349Scael.Fa size .
24*48349ScaelThe
25*48349Scael.Fn malloc
26*48349Scaelfunction maintains multiple lists of free blocks according to size, allocating
27*48349Scaelspace from the appropriate list.
28*48349Scael.Pp
29*48349ScaelThe allocated space is
30*48349Scaelsuitably aligned (after possible pointer
31*48349Scaelcoercion) for storage of any type of object. If the space is of
32*48349Scael.Em pagesize
3328178Skarelsor larger, the memory returned will be page-aligned.
34*48349Scael.Sh RETURN VALUES
35*48349ScaelThe
36*48349Scael.Fn malloc
37*48349Scaelfunction returns
38*48349Scaela pointer to the allocated space if successful; otherwise
39*48349Scaela null pointer is returned.
40*48349Scael.Sh SEE ALSO
41*48349Scael.Xr brk 2 ,
42*48349Scael.Xr pagesize 2
43*48349Scael.Xr free 3 ,
44*48349Scael.Xr calloc 3 ,
45*48349Scael.Xr alloca 3 ,
46*48349Scael.Xr realloc 3 ,
47*48349Scael.Xr memory 3
48*48349Scael.Sh STANDARDS
49*48349ScaelThe
50*48349Scael.Fn malloc
51*48349Scaelfunction conforms to
52*48349Scael.St -ansiC .
53*48349Scael.Sh BUGS
5428178SkarelsThe current implementation of
55*48349Scael.Xr malloc
5628178Skarelsdoes not always fail gracefully when system
5728178Skarelsmemory limits are approached.
5828178SkarelsIt may fail to allocate memory when larger free blocks could be broken
5928178Skarelsup, or when limits are exceeded because the size is rounded up.
6028178SkarelsIt is optimized for sizes that are powers of two.
61