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