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"
40 posix_memalign, memalign, valloc \- アラインメントされたメモリの割り当てを行う
43 .B #include <stdlib.h>
45 .BI "int posix_memalign(void **" memptr ", size_t " alignment ", size_t " size );
47 .B #include <malloc.h>
49 .BI "void *valloc(size_t " size );
50 .BI "void *memalign(size_t " boundary ", size_t " size );
55 .RB ( feature_test_macros (7)
60 .BR posix_memalign ():
62 _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
73 (_XOPEN_SOURCE\ >=\ 500 ||
74 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
75 !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
80 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
81 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
90 バイトのメモリを割り当て、割り当てられたメモリのアドレスを
102 .BR posix_memalign ()
112 バイトのメモリを割り当て、割り当てられたメモリへのポインタを返す。
118 .\" The behavior of memalign() for size==0 is as for posix_memalign()
119 .\" but no standards govern this.
125 バイトのメモリを割り当て、割り当てられたメモリへのポインタを返す。
126 メモリのアドレスはページサイズの倍数になっているはずである。
128 .I "memalign(sysconf(_SC_PAGESIZE),size)"
131 .\" motoki: be not zeroed ってどういう意味?
132 3 つの関数はいずれもメモリのゼロクリアを行わない。
137 は割り当てられたメモリへのポインタを返す。
138 割り当てに失敗した場合は NULL を返す。
140 .BR posix_memalign ()
142 失敗した場合は次のセクションに記載されたエラー値のいずれかを返す。
154 割り当て要求を満たすのに十分なメモリがなかった。
159 はすべての Linux libc ライブラリで使用可能である。
160 .BR posix_memalign ()
161 は glibc 2.1.91 以降で使用可能である。
165 は 3.0BSD で登場した。4.3BSD では廃止されたと記載されており、
166 SUSv2 では過去の名残だと記載されている。
167 POSIX.1-2001 にはもはや存在しない。
170 は SunOS 4.1.3 で登場したが、4.4BSD にはない。
172 .BR posix_memalign ()
175 .BR posix_memalign ()
176 の宣言を \fI<stdlib.h>\fP で行うことに関しては、
181 は \fI<malloc.h>\fP ではなく \fI<stdlib.h>\fP で宣言されている。
200 .B _XOPEN_SOURCE_EXTENDED
204 が 500 より小さくない値に定義されている)。
206 多くのシステムでは、アラインメントに関して制限がある。例えば、
207 ブロックデバイスに対するダイレクト I/O に使用するバッファには
209 POSIX では、どんなアラインメントが必要かを知るために
210 .I "pathconf(path,_PC_REC_XFER_ALIGN)"
212 .BR posix_memalign ()
213 を使うと、この必要条件を満たすことができる。
215 .BR posix_memalign ()
218 が上で詳細に述べた必要条件を満たすかどうかを確かめる。
222 引き数が正しいかどうかの確認を行わないかもしれない。
225 .BR posix_memalign ()
233 で割り当てられたメモリを再利用する手段が提供されていない。
234 .\" motoki: while の前後のつながりはこれでいい?
244 を呼び出し、得た値をアラインメントしてしまうからである)
245 .\" Other systems allow passing the result of
252 ここに述べた 3 つの関数のいずれで獲得したメモリも
258 は常に 8 バイトにアラインメントされたメモリアドレスを返すので、
260 8 バイトよりも大きなアラインメントが必要な場合だけである。