1MALLOC(3P) POSIX Programmer's Manual MALLOC(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 malloc — a memory allocator
13
15 #include <stdlib.h>
16
17 void *malloc(size_t size);
18
20 The functionality described on this reference page is aligned with the
21 ISO C standard. Any conflict between the requirements described here
22 and the ISO C standard is unintentional. This volume of POSIX.1‐2017
23 defers to the ISO C standard.
24
25 The malloc() function shall allocate unused space for an object whose
26 size in bytes is specified by size and whose value is unspecified.
27
28 The order and contiguity of storage allocated by successive calls to
29 malloc() is unspecified. The pointer returned if the allocation suc‐
30 ceeds shall be suitably aligned so that it may be assigned to a pointer
31 to any type of object and then used to access such an object in the
32 space allocated (until the space is explicitly freed or reallocated).
33 Each such allocation shall yield a pointer to an object disjoint from
34 any other object. The pointer returned points to the start (lowest byte
35 address) of the allocated space. If the space cannot be allocated, a
36 null pointer shall be returned. If the size of the space requested is
37 0, the behavior is implementation-defined: either a null pointer shall
38 be returned, or the behavior shall be as if the size were some non-zero
39 value, except that the behavior is undefined if the returned pointer is
40 used to access an object.
41
43 Upon successful completion with size not equal to 0, malloc() shall
44 return a pointer to the allocated space. If size is 0, either:
45
46 * A null pointer shall be returned and errno may be set to an imple‐
47 mentation-defined value, or
48
49 * A pointer to the allocated space shall be returned. The application
50 shall ensure that the pointer is not used to access an object.
51
52 Otherwise, it shall return a null pointer and set errno to indicate the
53 error.
54
56 The malloc() function shall fail if:
57
58 ENOMEM Insufficient storage space is available.
59
60 The following sections are informative.
61
63 None.
64
66 None.
67
69 None.
70
72 None.
73
75 calloc(), free(), getrlimit(), posix_memalign(), realloc()
76
77 The Base Definitions volume of POSIX.1‐2017, <stdlib.h>
78
80 Portions of this text are reprinted and reproduced in electronic form
81 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
82 table Operating System Interface (POSIX), The Open Group Base Specifi‐
83 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
84 Electrical and Electronics Engineers, Inc and The Open Group. In the
85 event of any discrepancy between this version and the original IEEE and
86 The Open Group Standard, the original IEEE and The Open Group Standard
87 is the referee document. The original Standard can be obtained online
88 at http://www.opengroup.org/unix/online.html .
89
90 Any typographical or formatting errors that appear in this page are
91 most likely to have been introduced during the conversion of the source
92 files to man page format. To report such errors, see https://www.ker‐
93 nel.org/doc/man-pages/reporting_bugs.html .
94
95
96
97IEEE/The Open Group 2017 MALLOC(3P)