1MALLOC(P) POSIX Programmer's Manual MALLOC(P)
2
3
4
6 malloc - a memory allocator
7
9 #include <stdlib.h>
10
11 void *malloc(size_t size);
12
13
15 The malloc() function shall allocate unused space for an object whose
16 size in bytes is specified by size and whose value is unspecified.
17
18 The order and contiguity of storage allocated by successive calls to
19 malloc() is unspecified. The pointer returned if the allocation suc‐
20 ceeds shall be suitably aligned so that it may be assigned to a pointer
21 to any type of object and then used to access such an object in the
22 space allocated (until the space is explicitly freed or reallocated).
23 Each such allocation shall yield a pointer to an object disjoint from
24 any other object. The pointer returned points to the start (lowest byte
25 address) of the allocated space. If the space cannot be allocated, a
26 null pointer shall be returned. If the size of the space requested is
27 0, the behavior is implementation-defined: the value returned shall be
28 either a null pointer or a unique pointer.
29
31 Upon successful completion with size not equal to 0, malloc() shall
32 return a pointer to the allocated space. If size is 0, either a null
33 pointer or a unique pointer that can be successfully passed to free()
34 shall be returned. Otherwise, it shall return a null pointer and set
35 errno to indicate the error.
36
38 The malloc() function shall fail if:
39
40 ENOMEM Insufficient storage space is available.
41
42
43 The following sections are informative.
44
46 None.
47
49 None.
50
52 None.
53
55 None.
56
58 calloc() , free() , realloc() , the Base Definitions volume of
59 IEEE Std 1003.1-2001, <stdlib.h>
60
62 Portions of this text are reprinted and reproduced in electronic form
63 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
64 -- Portable Operating System Interface (POSIX), The Open Group Base
65 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
66 Electrical and Electronics Engineers, Inc and The Open Group. In the
67 event of any discrepancy between this version and the original IEEE and
68 The Open Group Standard, the original IEEE and The Open Group Standard
69 is the referee document. The original Standard can be obtained online
70 at http://www.opengroup.org/unix/online.html .
71
72
73
74IEEE/The Open Group 2003 MALLOC(P)