1 .\" Copyright (c) 2001 by John Levon <moz@compsoc.man.ac.uk>
2 .\" Based in part on GNU libc documentation.
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" 2001-10-11, 2003-08-22, aeb, added some details
27 .\" Japanese Version Copyright (c) 2001 Akihiro MOTOKI
28 .\" all rights reserved.
29 .\" Translated 2001-11-05, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
30 .\" Updated 2003-09-05, Akihiro MOTOKI, catch up to v1.60
31 .\" Updated 2005-11-19, Akihiro MOTOKI
32 .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24
34 .\"WORD: obsolete Çѻߤµ¤ì¤¿
35 .\"WORD: a multiple of ¡Á¤ÎÇÜ¿ô
36 .\"WORD: a power of two 2 ¤Î¤Ù¤¾è
38 .TH POSIX_MEMALIGN 3 2010-09-20 "GNU" "Linux Programmer's Manual"
41 .\"O posix_memalign, memalign, valloc \- Allocate aligned memory
42 posix_memalign, memalign, valloc \- ¥¢¥é¥¤¥ó¥á¥ó¥È¤µ¤ì¤¿¥á¥â¥ê¤Î³ä¤êÅö¤Æ¤ò¹Ô¤¦
46 .B #include <stdlib.h>
48 .BI "int posix_memalign(void **" memptr ", size_t " alignment ", size_t " size );
50 .B #include <malloc.h>
52 .BI "void *valloc(size_t " size );
53 .BI "void *memalign(size_t " boundary ", size_t " size );
57 .\"O Feature Test Macro Requirements for glibc (see
58 .\"O .BR feature_test_macros (7)):
59 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
60 .RB ( feature_test_macros (7)
65 .BR posix_memalign ():
67 _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
75 .\"O Since glibc 2.12:
79 (_XOPEN_SOURCE\ >=\ 500 ||
80 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
81 !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
85 .\"O Before glibc 2.12:
87 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
88 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
95 .\"O .BR posix_memalign ()
98 .\"O bytes and places the address of the allocated memory in
100 .\"O The address of the allocated memory will be a multiple of
101 .\"O .IR "alignment" ,
102 .\"O which must be a power of two and a multiple of
103 .\"O .IR "sizeof(void *)".
105 .BR posix_memalign ()
108 ¥Ð¥¤¥È¤Î¥á¥â¥ê¤ò³ä¤êÅö¤Æ¡¢³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Î¥¢¥É¥ì¥¹¤ò
111 ³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Î¥¢¥É¥ì¥¹¤Ï
113 ¤ÎÇÜ¿ô¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤Ï¤º¤Ç¤¢¤ë¡£
115 ¤Ï 2 ¤Î¤Ù¤¾è¤Ç¡¢¤«¤Ä
117 ¤ÎÇÜ¿ô¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
121 .\"O .BR posix_memalign ()
122 .\"O returns either NULL,
123 .\"O .\" glibc does this:
124 .\"O or a unique pointer value that can later be successfully passed to
128 .BR posix_memalign ()
129 ¤Ï NULL ¤«°ì°Õ¤Ê¥Ý¥¤¥ó¥¿ÃͤòÊÖ¤¹¡£
130 ¤³¤Î¥Ý¥¤¥ó¥¿Ãͤϡ¢¸å¤Ç
132 ¤ËÌäÂê¤Ê¤¯ÅϤ¹¤³¤È¤¬¤Ç¤¤ë¡£
134 .\"O The obsolete function
138 .\"O bytes and returns a pointer to the allocated memory.
139 .\"O The memory address will be a multiple of
140 .\"O .IR "boundary" ,
141 .\"O which must be a power of two.
146 ¥Ð¥¤¥È¤Î¥á¥â¥ê¤ò³ä¤êÅö¤Æ¡¢³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
149 ¤ÎÇÜ¿ô¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤Ï¤º¤Ç¤¢¤ë¡£
151 ¤Ï 2 ¤Î¤Ù¤¾è¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
152 .\" The behavior of memalign() for size==0 is as for posix_memalign()
153 .\" but no standards govern this.
155 .\"O The obsolete function
159 .\"O bytes and returns a pointer to the allocated memory.
160 .\"O The memory address will be a multiple of the page size.
161 .\"O It is equivalent to
162 .\"O .IR "memalign(sysconf(_SC_PAGESIZE),size)" .
167 ¥Ð¥¤¥È¤Î¥á¥â¥ê¤ò³ä¤êÅö¤Æ¡¢³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
168 ¥á¥â¥ê¤Î¥¢¥É¥ì¥¹¤Ï¥Ú¡¼¥¸¥µ¥¤¥º¤ÎÇÜ¿ô¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤Ï¤º¤Ç¤¢¤ë¡£
170 .I "memalign(sysconf(_SC_PAGESIZE),size)"
173 .\"O For all three routines, the memory is not zeroed.
174 .\" motoki: be not zeroed ¤Ã¤Æ¤É¤¦¤¤¤¦°ÕÌ£¡©
175 3 ¤Ä¤Î´Ø¿ô¤Ï¤¤¤º¤ì¤â¥á¥â¥ê¤Î¥¼¥í¥¯¥ê¥¢¤ò¹Ô¤ï¤Ê¤¤¡£
176 .\"O .SH "RETURN VALUE"
181 .\"O return the pointer to the allocated memory, or NULL if the request fails.
185 ¤Ï³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
186 ³ä¤êÅö¤Æ¤Ë¼ºÇÔ¤·¤¿¾ì¹ç¤Ï NULL ¤òÊÖ¤¹¡£
188 .\"O .BR posix_memalign ()
189 .\"O returns zero on success, or one of the error values listed in the
190 .\"O next section on failure.
194 .BR posix_memalign ()
195 ¤ÏÀ®¸ù¤·¤¿¾ì¹ç¤Ï 0 ¤òÊÖ¤·¡¢
196 ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï¼¡¤Î¥»¥¯¥·¥ç¥ó¤ËµºÜ¤µ¤ì¤¿¥¨¥é¡¼ÃͤΤ¤¤º¤ì¤«¤òÊÖ¤¹¡£
198 ¤Ï¥»¥Ã¥È¤µ¤ì¤Ê¤¤¤³¤È¤ËÃí°Õ¤¹¤ë¤³¤È¡£
205 .\"O argument was not a power of two, or was not a multiple of
206 .\"O .IR "sizeof(void *)" .
208 °ú¤¿ô¤¬ 2 ¤Î¤Ù¤¾è¤Ç¤Ê¤«¤Ã¤¿¤«¡¢
213 .\"O There was insufficient memory to fulfill the allocation request.
214 ³ä¤êÅö¤ÆÍ×µá¤òËþ¤¿¤¹¤Î¤Ë½½Ê¬¤Ê¥á¥â¥ê¤¬¤Ê¤«¤Ã¤¿¡£
221 .\"O have been available in all Linux libc libraries.
225 ¤Ï¤¹¤Ù¤Æ¤Î Linux libc ¥é¥¤¥Ö¥é¥ê¤Ç»ÈÍѲÄǽ¤Ç¤¢¤ë¡£
227 .\"O .BR posix_memalign ()
228 .\"O is available since glibc 2.1.91.
229 .BR posix_memalign ()
230 ¤Ï glibc 2.1.91 °Ê¹ß¤Ç»ÈÍѲÄǽ¤Ç¤¢¤ë¡£
231 .\"O .SH "CONFORMING TO"
235 .\"O appeared in 3.0BSD.
236 .\"O It is documented as being obsolete in 4.3BSD,
237 .\"O and as legacy in SUSv2.
238 .\"O It does not appear in POSIX.1-2001.
241 ¤Ï 3.0BSD ¤ÇÅо줷¤¿¡£4.3BSD ¤Ç¤ÏÇѻߤµ¤ì¤¿¤ÈµºÜ¤µ¤ì¤Æ¤ª¤ê¡¢
242 SUSv2 ¤Ç¤Ï²áµî¤Î̾»Ä¤À¤ÈµºÜ¤µ¤ì¤Æ¤¤¤ë¡£
243 POSIX.1-2001 ¤Ë¤Ï¤â¤Ï¤ä¸ºß¤·¤Ê¤¤¡£
246 .\"O appears in SunOS 4.1.3 but not in 4.4BSD.
249 ¤Ï SunOS 4.1.3 ¤ÇÅо줷¤¿¤¬¡¢4.4BSD ¤Ë¤Ï¤Ê¤¤¡£
251 .\"O .BR posix_memalign ()
252 .\"O comes from POSIX.1d.
254 .BR posix_memalign ()
255 ¤Ï POSIX.1d ¤ËͳÍ褹¤ë¡£
258 .\"O Everybody agrees that
259 .\"O .BR posix_memalign ()
260 .\"O is declared in \fI<stdlib.h>\fP.
261 .BR posix_memalign ()
262 ¤ÎÀë¸À¤ò \fI<stdlib.h>\fP ¤Ç¹Ô¤¦¤³¤È¤Ë´Ø¤·¤Æ¤Ï¡¢
263 ³§¤Î°Õ¸«¤¬°ìÃפ·¤Æ¤¤¤ë¡£
267 .\"O is declared in \fI<stdlib.h>\fP instead of \fI<malloc.h>\fP.
268 ¤¤¤¯¤Ä¤«¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
270 ¤Ï \fI<malloc.h>\fP ¤Ç¤Ï¤Ê¤¯ \fI<stdlib.h>\fP ¤ÇÀë¸À¤µ¤ì¤Æ¤¤¤ë¡£
272 .\"O According to SUSv2,
274 .\"O is declared in \fI<stdlib.h>\fP.
275 .\"O Libc4,5 and glibc declare it in \fI<malloc.h>\fP and perhaps also in
276 .\"O \fI<stdlib.h>\fP
283 .\"O .B _XOPEN_SOURCE_EXTENDED
284 .\"O is defined, or, equivalently,
285 .\"O .B _XOPEN_SOURCE
286 .\"O is defined to a value not less than 500).
292 libc4,5 ¤ä glibc ¤Ç¤Ï
297 ¤Ç¤âÀë¸À¤µ¤ì¤ë¤³¤È¤â¤¢¤ë
298 (¶ñÂÎŪ¤Ë¤Ï°Ê²¼¤Î¤¤¤º¤ì¤«¤Î¾ì¹ç:
304 .B _XOPEN_SOURCE_EXTENDED
308 ¤¬ 500 ¤è¤ê¾®¤µ¤¯¤Ê¤¤ÃͤËÄêµÁ¤µ¤ì¤Æ¤¤¤ë)¡£
311 .\"O On many systems there are alignment restrictions, for example, on buffers
312 .\"O used for direct block device I/O.
313 .\"O POSIX specifies the
314 .\"O .I "pathconf(path,_PC_REC_XFER_ALIGN)"
315 .\"O call that tells what alignment is needed.
317 .\"O .BR posix_memalign ()
318 .\"O to satisfy this requirement.
319 ¿¤¯¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¥¢¥é¥¤¥ó¥á¥ó¥È¤Ë´Ø¤·¤ÆÀ©¸Â¤¬¤¢¤ë¡£Î㤨¤Ð¡¢
320 ¥Ö¥í¥Ã¥¯¥Ç¥Ð¥¤¥¹¤ËÂФ¹¤ë¥À¥¤¥ì¥¯¥È I/O ¤Ë»ÈÍѤ¹¤ë¥Ð¥Ã¥Õ¥¡¤Ë¤Ï
321 ¥¢¥é¥¤¥ó¥á¥ó¥È¤Ë´Ø¤¹¤ëÀ©¸Â¤¬¤¢¤ë¡£
322 POSIX ¤Ç¤Ï¡¢¤É¤ó¤Ê¥¢¥é¥¤¥ó¥á¥ó¥È¤¬É¬Íפ«¤òÃΤ뤿¤á¤Ë
323 .I "pathconf(path,_PC_REC_XFER_ALIGN)"
324 ¥³¡¼¥ë¤òµ¬Äꤷ¤Æ¤¤¤ë¡£¤³¤³¤Ç
325 .BR posix_memalign ()
326 ¤ò»È¤¦¤È¡¢¤³¤ÎɬÍ×¾ò·ï¤òËþ¤¿¤¹¤³¤È¤¬¤Ç¤¤ë¡£
328 .\"O .BR posix_memalign ()
331 .\"O matches the requirements detailed above.
332 .BR posix_memalign ()
335 ¤¬¾å¤Ç¾ÜºÙ¤Ë½Ò¤Ù¤¿É¬Í×¾ò·ï¤òËþ¤¿¤¹¤«¤É¤¦¤«¤ò³Î¤«¤á¤ë¡£
337 .\"O may not check that the
339 .\"O argument is correct.
343 °ú¤¿ô¤¬Àµ¤·¤¤¤«¤É¤¦¤«¤Î³Îǧ¤ò¹Ô¤ï¤Ê¤¤¤«¤â¤·¤ì¤Ê¤¤¡£
345 .\"O POSIX requires that memory obtained from
346 .\"O .BR posix_memalign ()
347 .\"O can be freed using
350 .BR posix_memalign ()
351 ¤Ë¤è¤Ã¤Æ³ÍÆÀ¤·¤¿¥á¥â¥ê¤Ï
353 ¤ò»È¤Ã¤Æ²òÊü¤¹¤ë¤³¤È¤¬¤Ç¤¤ëɬÍפ¬¤¢¤ë¡£
354 .\"O Some systems provide no way to reclaim memory allocated with
358 ¤¤¤¯¤Ä¤«¤Î¥·¥¹¥Æ¥à¤Ç¤Ï
362 ¤Ç³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤òºÆÍøÍѤ¹¤ë¼êÃʤ¬Ä󶡤µ¤ì¤Æ¤¤¤Ê¤¤¡£
363 .\"O (because one can only pass to
365 .\"O a pointer gotten from
367 .\"O while, for example,
371 .\"O and then align the obtained value).
372 .\" motoki: while ¤ÎÁ°¸å¤Î¤Ä¤Ê¤¬¤ê¤Ï¤³¤ì¤Ç¤¤¤¤¡©
375 ¤ËÅϤ¹¤³¤È¤¬¤Ç¤¤ë¤Î¤Ï
377 ¤«¤é¼õ¤±¼è¤Ã¤¿¥Ý¥¤¥ó¥¿¤À¤±¤À¤¬¡¢
382 ¤ò¸Æ¤Ó½Ð¤·¡¢ÆÀ¤¿Ãͤò¥¢¥é¥¤¥ó¥á¥ó¥È¤·¤Æ¤·¤Þ¤¦¤«¤é¤Ç¤¢¤ë)
383 .\" Other systems allow passing the result of
389 .\"O The glibc implementation
390 .\"O allows memory obtained from any of these three routines to be
394 ¤³¤³¤Ë½Ò¤Ù¤¿ 3 ¤Ä¤Î´Ø¿ô¤Î¤¤¤º¤ì¤Ç³ÍÆÀ¤·¤¿¥á¥â¥ê¤â
396 ¤ÇºÆÍøÍѤ¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
400 .\"O always returns 8-byte aligned memory addresses, so these routines are only
401 .\"O needed if you require larger alignment values.
404 ¤Ï¾ï¤Ë 8 ¥Ð¥¤¥È¤Ë¥¢¥é¥¤¥ó¥á¥ó¥È¤µ¤ì¤¿¥á¥â¥ê¥¢¥É¥ì¥¹¤òÊÖ¤¹¤Î¤Ç¡¢
405 ¤³¤³¤Ç½Ò¤Ù¤¿´Ø¿ô¤¬É¬Íפˤʤë¤Î¤Ï
406 8 ¥Ð¥¤¥È¤è¤ê¤âÂ礤ʥ¢¥é¥¤¥ó¥á¥ó¥È¤¬É¬Íפʾì¹ç¤À¤±¤Ç¤¢¤ë¡£