summaryrefslogtreecommitdiffstats
path: root/man3/malloc.3
blob: 84255bf4bf883599a1cbea9c6fcd54b5101106e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
.\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
.\" This file can be distributed under the terms of the GNU General Public
.\" License.
.\" Modified Sat Jul 24 19:00:59 1993 by Rik Faith (faith@cs.unc.edu)
.TH MALLOC 3  "April 4, 1993" "GNU" "Linux Programmer's Manual"
.SH NAME
calloc, malloc, free, realloc \- Allocate and free dynamic memory
.SH SYNOPSIS
.nf
.B #include <stdlib.h>
.sp
.BI "void *calloc(size_t " "nmemb" ", size_t " "size" ");"
.nl
.BI "void *malloc(size_t " "size" ");"
.nl
.BI "void free(void " "*ptr" ");"
.nl
.BI "void *realloc(void " "*ptr" ", size_t "  "size" ");"
.fi
.SH DESCRIPTION
.B calloc()
allocates memory for an array of 
.I nmemb
elements of 
.I size
bytes each and returns a pointer to the allocated memory. 
The memory is set to zero.
.PP
.B malloc()
allocates
.I size
bytes and returns a pointer to the allocated memory. 
The memory ist not cleared.
.PP
.B free()
frees the memory space pointed to by
.IR ptr ,
which must have been returned by a previous call to
.BR malloc() ,
.B calloc()
or
.BR realloc() .
If
.I ptr
is
.BR NULL ,
no operation is performed.
.PP
.B realloc()
changes the size of the memory block pointed to by
.I ptr
to
.I size
bytes.
The contents will be unchanged to the minimum of the old an new sizes;
newly allocated memory will be uninitialized.
If
.I ptr
is
.BR NULL ,
the call is equivalent to
.BR malloc(size) ;
if size is equal to zero,
the call is equivalent to
.BI "free(" "ptr" ) .
Unless
.I ptr
is
.BR NULL ,
it must have been returned by an earlier call to
.BR malloc() ,
.BR calloc()
or
.BR realloc() .
.SH "RETURN VALUES"
For
.BR calloc() " and " malloc() ,
the value returned is a pointer to the allocated memory, which is suitably
aligned for any kind of variable, or
.B NULL
if the request fails.
.PP
.B free()
returns no value.
.PP
.B realloc()
returns a pointer to the newly allocated memory, which is suitably
aligned for any kind of variable and may be different from
.IR ptr ,
or
.B NULL
if the request fails or if size was equal to 0.
.SH "CONFORMS TO"
ANSI - C
.SH SEE ALSO
.BR brk (2)