OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man3 / malloc.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\" License.
23 .\" Modified Sat Jul 24 19:00:59 1993 by Rik Faith (faith@cs.unc.edu)
24 .\" Clarification concerning realloc, iwj10@cus.cam.ac.uk (Ian Jackson), 950701
25 .\" Documented MALLOC_CHECK_, Wolfram Gloger (wmglo@dent.med.uni-muenchen.de)
26 .\" 2007-09-15 mtk: added notes on malloc()'s use of sbrk() and mmap().
27 .\"
28 .\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved.
29 .\" Translated 1998-08-12, NAKANO Takeo <nakano@apm.seikei.ac.jp>
30 .\" Modified 1998-12-18, NAKANO Takeo
31 .\" Modified 2000-08-23, NAKANO Takeo
32 .\" Modified 2001-05-19, Kentaro Shirakata <argrath@ub32.org>
33 .\" Modified 2001-12-13, Kentaro Shirakata <argrath@ub32.org>
34 .\" Modified 2005-03-15, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
35 .\" Modified 2007-10-12, Akihiro MOTOKI, LDP v2.66
36 .\"
37 .\" WORD: OOM killer    ¥á¥â¥êÉÔ­²ò·è´ï
38 .\"
39 .TH MALLOC 3  2009-01-13 "GNU" "Linux Programmer's Manual"
40 .\"O .SH NAME
41 .\"O calloc, malloc, free, realloc \- Allocate and free dynamic memory
42 .SH Ì¾Á°
43 calloc, malloc, free, realloc \- Æ°Åª¤Ê¥á¥â¥ê¤Î³ä¤êÅö¤Æ¤È²òÊü¤ò¹Ô¤¦
44 .\"O .SH SYNOPSIS
45 .SH ½ñ¼°
46 .nf
47 .B #include <stdlib.h>
48 .sp
49 .BI "void *calloc(size_t " "nmemb" ", size_t " "size" );
50 .br
51 .BI "void *malloc(size_t " "size" );
52 .br
53 .BI "void free(void " "*ptr" );
54 .br
55 .BI "void *realloc(void " "*ptr" ", size_t "  "size" );
56 .fi
57 .\"O .SH DESCRIPTION
58 .SH ÀâÌÀ
59 .\"O .BR calloc ()
60 .\"O allocates memory for an array of
61 .\"O .I nmemb
62 .\"O elements of
63 .\"O .I size
64 .\"O bytes each and returns a pointer to the allocated memory.
65 .\"O The memory is set to zero.
66 .BR calloc ()
67 ¤Ï
68 .I size
69 ¥Ð¥¤¥È¤ÎÍ×ÁÇ
70 .I nmemb
71 ¸Ä¤«¤é¤Ê¤ëÇÛÎó¤Ë¥á¥â¥ê¤ò³ä¤êÅö¤Æ¡¢
72 ³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤ËÂФ¹¤ë¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
73 ¥á¥â¥ê¤ÎÆâÍƤϿôÃÍ¥¼¥í (Á´¥Ó¥Ã¥È¤¬¥¼¥í¤Î¥Ð¥¤¥È) ¤Ë¥»¥Ã¥È¤µ¤ì¤ë¡£
74 .\"O If
75 .\"O .I nmemb
76 .\"O or
77 .\"O .I size
78 .\"O is 0, then
79 .\"O .BR calloc ()
80 .\"O returns either NULL,
81 .\"O .\" glibc does this:
82 .\"O or a unique pointer value that can later be successfully passed to
83 .\"O .BR free ().
84 .I nmemb
85 ¤«
86 .I size
87 ¤¬ 0 ¤Î¾ì¹ç¡¢
88 .BR calloc ()
89 ¤Ï NULL
90 .\" glibc ¤Ï¤³¤Á¤é
91 ¤Þ¤¿¤Ï
92 .BR free ()
93 ¤Ë¸å¤ÇÅϤ·¤Æ¤âÌäÂê¤Îµ¯¤³¤é¤Ê¤¤°ì°Õ¤Ê¥Ý¥¤¥ó¥¿ÃͤòÊÖ¤¹¡£
94 .PP
95 .\"O .BR malloc ()
96 .\"O allocates
97 .\"O .I size
98 .\"O bytes and returns a pointer to the allocated memory.
99 .\"O The memory is not cleared.
100 .BR malloc ()
101 ¤Ï
102 .I size
103 ¥Ð¥¤¥È¤ò³ä¤êÅö¤Æ¡¢
104 ³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤ËÂФ¹¤ë¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
105 ¥á¥â¥ê¤ÎÆâÍƤϥ¯¥ê¥¢¤µ¤ì¤Ê¤¤¡£
106 .\"O If
107 .\"O .I size
108 .\"O is 0, then
109 .\"O .BR malloc ()
110 .\"O returns either NULL,
111 .\"O .\" glibc does this:
112 .\"O or a unique pointer value that can later be successfully passed to
113 .\"O .BR free ().
114 .I size
115 ¤¬ 0 ¤Î¾ì¹ç¡¢
116 .BR malloc ()
117 ¤Ï NULL
118 .\" glibc ¤Ï¤³¤Á¤é
119 ¤Þ¤¿¤Ï
120 .BR free ()
121 ¤Ë¸å¤ÇÅϤ·¤Æ¤âÌäÂê¤Îµ¯¤³¤é¤Ê¤¤°ì°Õ¤Ê¥Ý¥¤¥ó¥¿ÃͤòÊÖ¤¹¡£
122 .PP
123 .\"O .BR free ()
124 .\"O frees the memory space pointed to by
125 .\"O .IR ptr ,
126 .\"O which must have been returned by a previous call to
127 .\"O .BR malloc (),
128 .\"O .BR calloc ()
129 .\"O or
130 .\"O .BR realloc ().
131 .\"O Otherwise, or if
132 .\"O .I free(ptr)
133 .\"O has already been called before, undefined behavior occurs.
134 .\"O If
135 .\"O .I ptr
136 .\"O is NULL, no operation is performed.
137 .BR free ()
138 ¤Ï¥Ý¥¤¥ó¥¿
139 .I ptr
140 ¤¬»Ø¤¹¥á¥â¥ê¶õ´Ö¤ò²òÊü¤¹¤ë¡£¤³¤Î¥Ý¥¤¥ó¥¿¤Ï¡¢°ÊÁ°¤Ë¸Æ¤Ó½Ð¤µ¤ì¤¿
141 .BR malloc (),
142 .BR calloc (),
143 .BR realloc ()
144 ¤Î¤¤¤º¤ì¤«¤¬ÊÖ¤·¤¿ÃͤǤʤ±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
145 ¤³¤ì°Ê³°¤Î¥Ý¥¤¥ó¥¿¤ò»ØÄꤷ¤¿¤ê¡¢¤¹¤Ç¤Ë
146 .I free(ptr)
147 ¤¬¼Â¹Ô¤µ¤ì¤Æ¤¤¤¿¤ê¤·¤¿¾ì¹ç¤ÎÆ°ºî¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
148 .I ptr
149 ¤¬ NULL ¤Î¾ì¹ç¤Ë¤Ï¡¢¤Ê¤ó¤ÎÆ°ºî¤â¹Ô¤ï¤ì¤Ê¤¤¡£
150 .PP
151 .\"O .BR realloc ()
152 .\"O changes the size of the memory block pointed to by
153 .\"O .I ptr
154 .\"O to
155 .\"O .I size
156 .\"O bytes.
157 .BR realloc ()
158 ¤Ï¡¢¥Ý¥¤¥ó¥¿
159 .I ptr
160 ¤¬¼¨¤¹¥á¥â¥ê¥Ö¥í¥Ã¥¯¤Î¥µ¥¤¥º¤òÊѹ¹¤·¤Æ
161 .I size
162 ¥Ð¥¤¥È¤Ë¤¹¤ë¡£
163 .\"O The contents will be unchanged to the minimum of the old and new sizes;
164 .\"O newly allocated memory will be uninitialized.
165 ¿·µì¤Î¥µ¥¤¥º¤Î¤¦¤Á¡¢¾®¤µ¤¤¤Û¤¦¤Î¥Ö¥í¥Ã¥¯¤Ë´Þ¤Þ¤ì¤ëÆâÍƤÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
166 ¿·¤·¤¯³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤ÎÆâÍƤϽé´ü²½¤µ¤ì¤Ê¤¤¡£
167 .\"O If
168 .\"O .I ptr
169 .\"O is NULL, then the call is equivalent to
170 .\"O .IR malloc(size) ,
171 .\"O for all values of
172 .\"O .IR size ;
173 .\"O if
174 .\"O .I size
175 .\"O is equal to zero,
176 .\"O and
177 .\"O .I ptr
178 .\"O is not NULL, then the call is equivalent to
179 .\"O .IR free(ptr) .
180 .I size
181 ¤¬¤É¤ÎÃͤǤ¢¤Ã¤Æ¤â¡¢
182 .I ptr
183 ¤¬ NULL ¤Î¾ì¹ç¤Ë¤Ï
184 .I malloc(size)
185 ¤ÈÅù²Á¤Ç¤¢¤ë¡£
186 .I size
187 ¤¬ 0 ¤Ç
188 .I ptr
189 ¤¬ NULL ¤Ç¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢
190 .I free(ptr)
191 ¤ÈÅù²Á¤Ç¤¢¤ë¡£
192 .\"O Unless
193 .\"O .I ptr
194 .\"O is NULL, it must have been returned by an earlier call to
195 .\"O .BR malloc (),
196 .\"O .BR calloc ()
197 .\"O or
198 .\"O .BR realloc ().
199 .I ptr
200 ¤¬ NULL °Ê³°¤Î¾ì¹ç¡¢
201 .I ptr
202 ¤Ï°ÊÁ°¤Ë¸Æ¤Ó½Ð¤µ¤ì¤¿
203 .BR malloc (),
204 .BR calloc (),
205 .BR realloc ()
206 ¤Î¤¤¤º¤ì¤«¤¬ÊÖ¤·¤¿ÃͤǤʤ±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
207 .\"O If the area pointed to was moved, a
208 .\"O .I free(ptr)
209 .\"O is done.
210 .I ptr
211 ¤¬»Ø¤¹Îΰ褬°ÜÆ°¤µ¤ì¤Æ¤¤¤¿¾ì¹ç¤Ï
212 .I free(ptr)
213 ¤¬¼Â¹Ô¤µ¤ì¤ë¡£
214 .\"O .SH "RETURN VALUE"
215 .SH ÊÖ¤êÃÍ
216 .\"O For
217 .\"O .BR calloc ()
218 .\"O and
219 .\"O .BR malloc (),
220 .\"O return a pointer to the allocated memory, which is suitably
221 .\"O aligned for any kind of variable.
222 .\"O On error, these functions return NULL.
223 .\"O NULL may also be returned by a successful call to
224 .\"O .BR malloc ()
225 .\"O with a
226 .\"O .I size
227 .\"O of zero,
228 .\"O or by a successful call to
229 .\"O .BR calloc ()
230 .\"O with
231 .\"O .I nmemb
232 .\"O or
233 .\"O .I size
234 .\"O equal to zero.
235 .BR calloc ()
236 ¤È
237 .BR malloc ()
238 ¤Ï¡¢³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
239 ³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ï¡¢¤¢¤é¤æ¤ë¼ïÎà¤ÎÊÑ¿ô¤ËÂбþ¤Ç¤­¤ë¤è¤¦¤Ë
240 ¥¢¥é¥¤¥ó¥á¥ó¥È¤µ¤ì¤Æ¤¤¤ë¡£
241 ¥¨¥é¡¼¤Î¾ì¹ç¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï NULL ¤òÊÖ¤¹¡£
242 .I size
243 ¤¬ 0 ¤Ç¸Æ¤Ó½Ð¤·¤¿
244 .BR malloc ()
245 ¤ä¡¢
246 .I nmemb
247 ¤«
248 .I size
249 ¤¬ 0 ¤Ç¸Æ¤Ó½Ð¤·¤¿
250 .BR calloc ()
251 ¤¬À®¸ù¤·¤¿¾ì¹ç¤Ë¤â NULL ¤¬ÊÖ¤µ¤ì¤ë¡£
252 .PP
253 .\"O .BR free ()
254 .\"O returns no value.
255 .BR free ()
256 ¤ÏÃͤòÊÖ¤µ¤Ê¤¤¡£
257 .PP
258 .\"O .BR realloc ()
259 .\"O returns a pointer to the newly allocated memory, which is suitably
260 .\"O aligned for any kind of variable and may be different from
261 .\"O .IR ptr ,
262 .\"O or NULL if the request fails.
263 .\"O If
264 .\"O .I size
265 .\"O was equal to 0, either NULL or a pointer suitable to be passed to
266 .\"O .BR free ()
267 .\"O is returned.
268 .\"O If
269 .\"O .BR realloc ()
270 .\"O fails the original block is left untouched; it is not freed or moved.
271 .BR realloc ()
272 ¤Ï¿·¤¿¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
273 ¤³¤ì¤Ï¤¢¤é¤æ¤ë¼ïÎà¤ÎÊÑ¿ô¤ËÂбþ¤Ç¤­¤ë¤è¤¦¤Ë¥¢¥é¥¤¥ó¥á¥ó¥È¤µ¤ì¤Æ¤ª¤ê¡¢
274 .I ptr
275 ¤È¤Ï°Û¤Ê¤ë¤³¤È¤â¤¢¤ë¡£
276 ³ä¤êÅö¤ÆÍ×µá¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¤Ï NULL ¤¬Ê֤롣
277 .I size
278 ¤¬ 0 ¤Î¾ì¹ç¤Ë¤Ï¡¢NULL ¤â¤·¤¯¤Ï
279 .BR free ()
280 ¤ËÅϤ¹¤³¤È¤¬¤Ç¤­¤ë¥Ý¥¤¥ó¥¿¤¬Ê֤롣
281 .BR realloc ()
282 ¤¬¼ºÇÔ¤·¤¿¾ì¹ç¤Ë¤Ï¡¢¸µ¤Î¥Ö¥í¥Ã¥¯¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
283 ¤Ä¤Þ¤ê¡¢²òÊü¤µ¤ì¤¿¤ê°ÜÆ°¤µ¤ì¤¿¤ê¤Ï¤·¤Ê¤¤¡£
284 .\"O .SH "CONFORMING TO"
285 .SH ½àµò
286 C89, C99.
287 .\"O .SH NOTES
288 .SH Ãí°Õ
289 .\"O Normally,
290 .\"O .BR malloc ()
291 .\"O allocates memory from the heap, and adjusts the size of the heap
292 .\"O as required, using
293 .\"O .BR sbrk (2).
294 Ä̾
295 .BR malloc ()
296 ¤Ï¡¢¥Ò¡¼¥×¤«¤é¥á¥â¥ê¤ò³ä¤êÅö¤Æ¡¢É¬Íפ˱þ¤¸¤Æ¥Ò¡¼¥×¤Î¥µ¥¤¥º¤ò
297 .BR sbrk (2)
298 ¤ò»È¤Ã¤ÆÄ´À᤹¤ë¡£
299 .\"O When allocating blocks of memory larger than
300 .\"O .B MMAP_THRESHOLD
301 .\"O bytes, the glibc
302 .\"O .BR malloc ()
303 .\"O implementation allocates the memory as a private anonymous mapping using
304 .\"O .BR mmap (2).
305 .\"O .B MMAP_THRESHOLD
306 .\"O is 128 kB by default, but is adjustable using
307 .\"O .BR mallopt (3).
308 .B MMAP_THRESHOLD
309 ¥Ð¥¤¥È¤è¤ê¤âÂ礭¤Ê¥á¥â¥ê¥Ö¥í¥Ã¥¯¤ò³ä¤êÅö¤Æ¤ë¾ì¹ç¡¢
310 glibc ¤Î
311 .BR malloc ()
312 ¼ÂÁõ¤Ï
313 .BR mmap (2)
314 ¤ò»È¤Ã¤Æ¥×¥é¥¤¥Ù¡¼¥È¤Ê̵̾¥Þ¥Ã¥Ô¥ó¥° (anonymous mapping) ¤È¤·¤Æ
315 ¥á¥â¥ê¤ò³ä¤êÅö¤Æ¤ë¡£
316 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï
317 .B MMAP_THRESHOLD
318 ¤Ï 128 kB ¤À¤¬¡¢
319 .BR mallopt (3)
320 ¤ò»È¤Ã¤ÆÄ´À°¤Ç¤­¤ë¡£
321 .\" FIXME . there is no mallopt(3) man page yet.
322 .\"O Allocations performed using
323 .\"O .BR mmap (2)
324 .\"O are unaffected by the
325 .\"O .B RLIMIT_DATA
326 .\"O resource limit (see
327 .\"O .BR getrlimit (2)).
328 .BR mmap (2)
329 ¤ò»È¤Ã¤Æ¹Ô¤ï¤ì¤¿¥á¥â¥ê³ä¤êÅö¤Æ¤Ï
330 .B RLIMIT_DATA
331 ¥ê¥½¡¼¥¹¾å¸Â¤Î±Æ¶Á¤ò¼õ¤±¤Ê¤¤
332 .RB ( getrlimit (2)
333 »²¾È)¡£
334
335 .\"O The Unix98 standard requires
336 .\"O .BR malloc (),
337 .\"O .BR calloc (),
338 .\"O and
339 .\"O .BR realloc ()
340 .\"O to set
341 .\"O .I errno
342 .\"O to
343 .\"O .B ENOMEM
344 .\"O upon failure.
345 .\"O Glibc assumes that this is done
346 .\"O (and the glibc versions of these routines do this); if you
347 .\"O use a private malloc implementation that does not set
348 .\"O .IR errno ,
349 .\"O then certain library routines may fail without having
350 .\"O a reason in
351 .\"O .IR errno .
352 Unix98 É¸½à¤Ç¤Ï¡¢
353 .BR malloc (),
354 .BR calloc (),
355 .BR realloc ()
356 ¤Ï¼Â¹Ô¤Ë¼ºÇÔ¤·¤¿¤È¤­¤Ë
357 .I errno
358 ¤ò
359 .B ENOMEM
360 ¤ËÀßÄꤹ¤ë¤³¤È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£
361 Glibc ¤Ç¤Ï¤³¤ì¤¬¼é¤é¤ì¤Æ¤¤¤ë¤³¤È¤ò²¾Äꤷ¤Æ¤¤¤ë
362 (¤Þ¤¿¤³¤ì¤é¤Î¥ë¡¼¥Á¥ó¤Î glibc ¥Ð¡¼¥¸¥ç¥ó¤Ï¤³¤Î¤³¤È¤ò¼é¤Ã¤Æ¤¤¤ë)¡£
363 ¸Ä¿ÍŪ¤ËÊ̤Πmalloc ¤Î¼ÂÁõ¤ò»È¤Ã¤Æ¤¤¤Æ¡¢¤½¤Î malloc ¤¬
364 .I errno
365 ¤òÀßÄꤷ¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢¼ºÇÔ¤·¤¿ºÝ¤Ë
366 .I errno
367 ¤Ë¥¨¥é¡¼¤ÎÍýͳ¤òÀßÄꤷ¤Ê¤¤¥é¥¤¥Ö¥é¥ê¥ë¡¼¥Á¥ó¤¬¤¢¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
368 .LP
369 .\"O Crashes in
370 .\"O .BR malloc (),
371 .\"O .BR calloc (),
372 .\"O .BR realloc (),
373 .\"O or
374 .\"O .BR free ()
375 .\"O are almost always related to heap corruption, such as overflowing
376 .\"O an allocated chunk or freeing the same pointer twice.
377 .BR malloc (),
378 .BR calloc (),
379 .BR realloc (),
380 .BR free ()
381 ¤Ë¤ª¤±¤ë»ö¸Î¤Ï¡¢
382 ¤Û¤È¤ó¤É¤Î¾ì¹ç¤Ï¥Ò¡¼¥×¤ÎÇ˲õ (corruption) ¤¬¸¶°ø¤Ç¤¢¤ë¡£
383 Î㤨¤Ð¡¢³ä¤êÅö¤Æ¤é¤ì¤¿Îΰè¤ò¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤¹¤ë¡¢
384 Ʊ¤¸¥Ý¥¤¥ó¥¿¤ËÆóÅÙ free ¤¹¤ë¡¢¤Ê¤É¤¬¤³¤ì¤Ë¤¢¤¿¤ë¡£
385 .PP
386 .\"O Recent versions of Linux libc (later than 5.4.23) and glibc (2.x)
387 .\"O include a
388 .\"O .BR malloc ()
389 .\"O implementation which is tunable via environment variables.
390 .\"O When
391 .\"O .B MALLOC_CHECK_
392 .\"O is set, a special (less efficient) implementation is used which
393 .\"O is designed to be tolerant against simple errors, such as double
394 .\"O calls of
395 .\"O .BR free ()
396 .\"O with the same argument, or overruns of a single byte (off-by-one
397 .\"O bugs).
398 .\"O Not all such errors can be protected against, however, and
399 .\"O memory leaks can result.
400 ºÇ¶á¤Î¥Ð¡¼¥¸¥ç¥ó¤Î Linux libc (5.4.23 °Ê¹ß) ¤È glibc (2.x) ¤Ç¤Ï¡¢
401 .BR malloc ()
402 ¤ÎÆ°ºî¤ò´Ä¶­ÊÑ¿ô¤Ë¤è¤Ã¤ÆÀ©¸æ¤Ç¤­¤ë¤è¤¦¤Ê¼ÂÁõ¤¬¤µ¤ì¤Æ¤¤¤ë¡£
403 .B MALLOC_CHECK_
404 ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¤È¡¢Æüì¤Ê¼ÂÁõ¤¬ÍѤ¤¤é¤ì¡¢
405 ñ½ã¤Ê¥¨¥é¡¼¤Ë¤ÏÂѤ¨¤ë¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤Ë¤Ê¤ë (¸úΨ¤Ï°­¤¯¤Ê¤ë)¡£Î㤨¤Ð¡¢
406 .BR free ()
407 ¤òƱ¤¸°ú¤­¿ô¤ÇÆóÅٸƤӽФ·¤Æ¤·¤Þ¤¦¡¢
408 1 ¥Ð¥¤¥È¤À¤±¹Ô¤­¤¹¤®¤Æ¤·¤Þ¤¦ (off-by-one ¥Ð¥°) ¤Ê¤É¤¬¤³¤ì¤ËÅö¤¿¤ë¡£
409 ¤·¤«¤·¡¢¤³¤ì¤é¤Î¥¨¥é¡¼¤ÎÁ´¤Æ¤òËɤ°¤³¤È¤¬¤Ç¤­¤ë¤ï¤±¤Ç¤Ï¤Ê¤¯¡¢
410 ¤½¤Î¾ì¹ç¤Ë¤Ï¥á¥â¥ê¥ê¡¼¥¯¤¬µ¯¤³¤Ã¤Æ¤·¤Þ¤¦¡£
411 .\"O If
412 .\"O .B MALLOC_CHECK_
413 .\"O is set to 0, any detected heap corruption is silently ignored;
414 .\"O if set to 1, a diagnostic is printed on \fIstderr\fP;
415 .\"O if set to 2,
416 .\"O .BR abort (3)
417 .\"O is called immediately;
418 .\"O if set to 3, a diagnostic message is printed on \fIstderr\fP
419 .\"O and the program is aborted.
420 .\"O Using a nonzero
421 .\"O .B MALLOC_CHECK_
422 .\"O value can be useful because otherwise
423 .\"O a crash may happen much later, and the true cause for the problem
424 .\"O is then very hard to track down.
425 .B MALLOC_CHECK_
426 ¤¬ 0 ¤Ë¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¤È¡¢¥Ò¡¼¥×¤ÎÇ˲õ¤òÌۤäÆ̵»ë¤¹¤ë¡£
427 1 ¤Ë¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¤È¡¢¿ÇÃÇ¥á¥Ã¥»¡¼¥¸¤¬É¸½à¥¨¥é¡¼½ÐÎϤËɽ¼¨¤µ¤ì¤ë¡£
428 2 ¤Ë¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¤È¡¢¤¿¤À¤Á¤Ë
429 .BR abort (3)
430 ¤¬¸Æ¤Ó½Ð¤µ¤ì¤ë¡£
431 3 ¤Ë¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¤È¡¢¿ÇÃÇ¥á¥Ã¥»¡¼¥¸¤¬É¸½à¥¨¥é¡¼½ÐÎϤËɽ¼¨¤µ¤ì¡¢
432 ¥×¥í¥°¥é¥à¤Ï¶¯À©½ªÎ» (abort) ¤µ¤ì¤ë¡£
433 .B MALLOC_CHECK_
434 ¤Ë 0 °Ê³°¤ÎÃͤò¥»¥Ã¥È¤·¤ÆÌò¤ËΩ¤Ä¾õ¶·¤È¤·¤Æ¤Ï¡¢
435 ¼ÂºÝ¤Î¥×¥í¥»¥¹¤Î¥¯¥é¥Ã¥·¥å¤¬¤º¤Ã¤È¸å¤Ëµ¯¤³¤ê¡¢
436 ËÜÅö¤Î¸¶°ø¤òõ¤·½Ð¤¹¤Î¤¬Èó¾ï¤Ëº¤Æñ¤Ê¾ì¹ç¤Ê¤É¤¬µó¤²¤é¤ì¤ë¤À¤í¤¦¡£
437 .\"O .SH BUGS
438 .SH ¥Ð¥°
439 .\"O By default, Linux follows an optimistic memory allocation strategy.
440 ¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢Linux ¤Ï³Ú´ÑŪ¥á¥â¥êÇÛÃÖÀïά¤òÍѤ¤¤Æ¤¤¤ë¡£
441 .\"O This means that when
442 .\"O .BR malloc ()
443 .\"O returns non-NULL there is no guarantee that the memory really
444 .\"O is available.
445 .\"O This is a really bad bug.
446 .\"O In case it turns out that the system is out of memory,
447 .\"O one or more processes will be killed by the infamous OOM killer.
448 ¤Ä¤Þ¤ê¡¢
449 .BR malloc ()
450 ¤¬ NULL ¤Ç¤Ê¤¤ÃͤòÊÖ¤·¤Æ¤â¡¢¤½¤Î¥á¥â¥ê¤¬¼ÂºÝ¤ËÍøÍѲÄǽ¤Ç¤¢¤ë¤³¤È¤¬
451 Êݾڤµ¤ì¤Ê¤¤¡£¤³¤ì¤ÏËÜÅö¤Ë¤Þ¤º¤¤¥Ð¥°¤Ç¤¢¤ë¡£
452 ¥·¥¹¥Æ¥à¤¬¥á¥â¥êÉÔ­¾õÂ֤ˤʤ俤Ȥ­¡¢°­Ì¾¹â¤¤¥á¥â¥êÉÔ­²ò·è´ï (OOM killer)
453 ¤Ë¤è¤Ã¤Æ°ì¤Ä¤Þ¤¿¤ÏÊ£¿ô¤Î¥×¥í¥»¥¹¤¬ºï½ü¤µ¤ì¤ë¡£
454 .\"O In case Linux is employed under circumstances where it would be
455 .\"O less desirable to suddenly lose some randomly picked processes,
456 .\"O and moreover the kernel version is sufficiently recent,
457 .\"O one can switch off this overcommitting behavior using a command like:
458 ÆÍÁ³¤¢¤ë¥×¥í¥»¥¹¤¬ºï½ü¤µ¤ì¤ë¤Î¤¬Ë¾¤Þ¤·¤¯¤Ê¤¤¾õ¶·¤Ç»ÈÍѤµ¤ì¤Æ¤¤¤Æ¡¢
459 ¤·¤«¤â¥«¡¼¥Í¥ë¤Î¥Ð¡¼¥¸¥ç¥ó¤¬½½Ê¬¤ËºÇ¶á¤Î¤â¤Î¤Ç¤¢¤ì¤Ð¡¢¤³¤Î¥á¥â¥ê¤ò
460 ³ä¤êÅö¤Æ²á¤®¤ëÆ°ºî (overcommitting behavior) ¤ò°Ê²¼¤Î¥³¥Þ¥ó¥É¤Ç
461 ̵¸ú¤Ë¤Ç¤­¤ë¡£
462 .in +4n
463 .sp
464 .nf
465 .RB "#" " echo 2 > /proc/sys/vm/overcommit_memory"
466
467 .fi
468 .in
469 .\"O See also the kernel Documentation directory, files
470 .\"O .I vm/overcommit-accounting
471 .\"O and
472 .\"O .IR sysctl/vm.txt .
473 ¥«¡¼¥Í¥ë¤ÎÉÕ°ʸ½ñ¤Î
474 .I vm/overcommit-accounting
475 ¤È
476 .I sysctl/vm.txt
477 ¤â»²¾È¤Î¤³¤È¡£
478 .\"O .SH "SEE ALSO"
479 .SH ´ØÏ¢¹àÌÜ
480 .BR brk (2),
481 .BR posix_memalign (3)
482 .\" .BR mallopt (3),
483 .BR mmap (2),
484 .BR alloca (3),