File: malloc.3

package info (click to toggle)
manpages-ja 0.5.0.0.20061115-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,788 kB
  • ctags: 4
  • sloc: sh: 13,215; perl: 157; makefile: 117
file content (201 lines) | stat: -rw-r--r-- 6,291 bytes parent folder | download
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
.\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\" 
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein.  The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\" 
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\" License.
.\" Modified Sat Jul 24 19:00:59 1993 by Rik Faith (faith@cs.unc.edu)
.\" Clarification concerning realloc, iwj10@cus.cam.ac.uk (Ian Jackson), 950701
.\" Documented MALLOC_CHECK_, Wolfram Gloger (wmglo@dent.med.uni-muenchen.de)
.\"
.\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
.\" Translated 1998-08-12, NAKANO Takeo <nakano@apm.seikei.ac.jp>
.\" Modified 1998-12-18, NAKANO Takeo
.\" Modified 2000-08-23, NAKANO Takeo
.\" Modified 2001-05-19, Kentaro Shirakata <argrath@ub32.org>
.\" Modified 2001-12-13, Kentaro Shirakata <argrath@ub32.org>
.\" Modified 2005-03-15, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\"
.\" WORD: OOM killer	­
.\"
.TH MALLOC 3  1993-04-04 "GNU" "Linux Programmer's Manual"
.SH ̾
calloc, malloc, free, realloc \- ưŪʥγƤȲԤ
.SH 
.nf
.B #include <stdlib.h>
.sp
.BI "void *calloc(size_t " "nmemb" ", size_t " "size" );
.br
.BI "void *malloc(size_t " "size" );
.br
.BI "void free(void " "*ptr" );
.br
.BI "void *realloc(void " "*ptr" ", size_t "  "size" );
.fi
.SH 
.BR calloc ()

.I size
ХȤ
.I nmemb
Ĥʤ˥ơ
Ƥ줿Фݥ󥿤֤
ƤϿͥ (ӥåȤΥХ) ˥åȤ롣
.PP
.BR malloc ()

.I size
ХȤơ
Ƥ줿Фݥ󥿤֤
Ƥϥꥢʤ
.PP
.BR free ()
ϥݥ
.I ptr
ؤ֤롣Υݥ󥿤ϡ˸ƤӽФ줿
.BR malloc (),
.BR calloc (),
.BR realloc ()
Τ줫֤ͤǤʤФʤʤ
ʳΥݥ󥿤ꤷꡢǤ
.BI "free(" "ptr" )
¹ԤƤꤷưƤʤ
.I ptr
 NULL ξˤϡʤưԤʤ
.PP
.BR realloc ()
ϡݥ
.I ptr
֥åΥѹ
.I size
ХȤˤ롣
ΥΤۤΥ֥å˴ޤޤƤѹʤ
Ƥ줿ƤϽʤ
.I ptr
 NULL ξˤ
.B malloc(size)
Ǥ롣
.I size
 0 ξˤ
.BI "free(" "ptr" )
Ǥ롣
.I ptr
 NULL ʳξ硢
.I ptr
ϰ˸ƤӽФ줿
.BR malloc (),
.BR calloc (),
.BR realloc ()
Τ줫֤ͤǤʤФʤʤ
.I ptr
ؤΰ褬ưƤ
.BI "free(" "ptr" )
¹Ԥ롣
.SH ֤
.BR calloc ()

.BR malloc ()
֤ͤϡƤ줿ؤΥݥ󥿤Ǥ롣
ϤѿбǤ褦˥饤ȤƤ롣
׵˼Ԥ NULL ֤롣
.PP
.BR free ()
֤ͤʤ
.PP
.BR realloc ()
Ͽ˳Ƥ줿ؤΥݥ󥿤֤
ϤѿбǤ褦˥饤ȤƤꡢ
.I ptr
Ȥϰۤʤ뤳Ȥ⤢롣
׵˼Ԥ NULL ֤롣
.I size
 0 ξˤϡNULL ⤷
.BR free ()
ϤȤǤݥ󥿤֤롣
.BR realloc ()
ԤˤϡΥ֥åѹʤ
Ĥޤꡢ줿ư줿Ϥʤ
.SH 
C89, C99.
.SH Ϣ
.BR brk (2),
.BR posix_memalign (3)
.SH 
Unix98 ɸǤϡ
.BR malloc (),
.BR calloc (),
.BR realloc ()
ϼ¹Ԥ˼ԤȤ
.I errno
 ENOMEM ꤹ뤳ȤˤʤäƤ롣
Glibc ǤϤ줬Ƥ뤳ȤꤷƤ
(ޤΥ롼 glibc СϤΤȤäƤ)
ĿṲ̄ malloc μȤäƤơ malloc 
.I errno
ꤷʤˤϡԤݤ
.I errno
˥顼ͳꤷʤ饤֥롼󤬤뤫⤷ʤ
.LP
.BR malloc (),
.BR free (),
.BR realloc ()
ʤɤˤΤϡ
ۤȤɤξϥҡפ˲ (corruption) Ǥ롣
㤨СƤ줿ΰ򥪡Сե롢
Ʊݥ󥿤 free 롢ʤɤˤ롣
.PP
ǶΥС Linux libc (5.4.23 ʹ)  GNU libc (2.x) Ǥϡ
malloc ưĶѿˤäǤ褦ʼƤ롣
.B MALLOC_CHECK_
ꤵƤȡüʼѤ졢
ñʥ顼ˤѤ뤳ȤǤ褦ˤʤ (Ψϰʤ)㤨С
.BR free ()
ƱٸƤӽФƤޤ
1 ХȤԤƤޤ (off-by-one Х) ʤɤ롣
Υ顼ƤɤȤǤ櫓ǤϤʤ
ξˤϥ꡼äƤޤ
.B MALLOC_CHECK_
 0 ˥åȤƤȡҡפ˲ۤä̵뤹롣
1 ˥åȤƤȡǥåɸ२顼Ϥɽ롣
2 ˥åȤƤȡ
.BR abort ()
ƤӽФ롣2 ꤷƤΩľȤƤϡ
ºݤΥץΥå夬äȸ˵ꡢ
θõФΤ˺ʾʤɤ󤲤
.SH Х
ǥեȤǤϡLinux ϳڴŪάѤƤ롣
Ĥޤꡢ
.BR malloc ()
 NULL Ǥʤ֤ͤƤ⡢Υ꤬ºݤѲǽǤ뤳Ȥ
ݾڤʤˤޤХǤ롣
ƥब­֤ˤʤäȤ̾⤤­ (OOM killer)
ˤäưĤޤʣΥץ롣
ץΤ˾ޤʤǻѤƤơ
⥫ͥΥС󤬽ʬ˺ǶΤΤǤСΥ
Ʋ᤮ư (overcommitting behavior) ʲΥޥɤ
̵ˤǤ롣
.RS
# echo 2 > /proc/sys/vm/overcommit_memory
.RE
ͥ°ʸ
.I vm/overcommit-accounting

.I sysctl/vm.txt
⻲ȤΤȡ