OSDN Git Service

(split) LDP: Restore and add Copyrights for draft pages
[linuxjm/LDP_man-pages.git] / draft / man3 / posix_memalign.3
1 .\" Copyright (c) 2001 by John Levon <moz@compsoc.man.ac.uk>
2 .\" Based in part on GNU libc documentation.
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" 2001-10-11, 2003-08-22, aeb, added some details
27 .\" 2012-03-23, Michael Kerrisk <mtk.manpages@mail.com>
28 .\"     Document pvalloc() and aligned_alloc()
29 .\"*******************************************************************
30 .\"
31 .\" This file was generated with po4a. Translate the source file.
32 .\"
33 .\"*******************************************************************
34 .\"
35 .\" Japanese Version Copyright (c) 2001 Akihiro MOTOKI
36 .\"       all rights reserved.
37 .\" Translated 2001-11-05, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
38 .\" Updated 2003-09-05, Akihiro MOTOKI, catch up to v1.60
39 .\" Updated 2005-11-19, Akihiro MOTOKI
40 .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24
41 .\" Updated 2012-05-01, Akihiro MOTOKI <amotoki@gmail.com>
42 .\" Updated 2012-05-08, Akihiro MOTOKI <amotoki@gmail.com>
43 .\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
44 .\" Updated 2013-07-22, Akihiro MOTOKI <amotoki@gmail.com>
45 .\"
46 .TH POSIX_MEMALIGN 3 2012\-03\-23 GNU "Linux Programmer's Manual"
47 .SH 名前
48 posix_memalign, aligned_alloc, memalign, valloc, pvalloc \- アラインメント
49 されたメモリの割り当てを行う
50 .SH 書式
51 .nf
52 \fB#include <stdlib.h>\fP
53 .sp
54 \fBint posix_memalign(void **\fP\fImemptr\fP\fB, size_t \fP\fIalignment\fP\fB, size_t \fP\fIsize\fP\fB);\fP
55 \fBvoid *aligned_alloc(size_t \fP\fIalignment\fP\fB, size_t \fP\fIsize\fP\fB);\fP
56 \fBvoid *valloc(size_t \fP\fIsize\fP\fB);\fP
57 .sp
58 \fB#include <malloc.h>\fP
59 .sp
60 \fBvoid *memalign(size_t \fP\fIalignment\fP\fB, size_t \fP\fIsize\fP\fB);\fP
61 \fBvoid *pvalloc(size_t \fP\fIsize\fP\fB);\fP
62 .fi
63 .sp
64 .in -4n
65 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
66 .in
67 .sp
68 .ad l
69 \fBposix_memalign\fP(): _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
70 .sp
71 \fBaligned_alloc\fP(): _ISOC11_SOURCE
72 .sp
73 \fBvalloc\fP():
74 .br
75 .PD 0
76 .RS 4
77 .TP  4
78 glibc 2.12 以降:
79 .nf
80 _BSD_SOURCE ||
81     (_XOPEN_SOURCE\ >=\ 500 ||
82         _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
83     !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
84 .br
85 .fi
86 .TP 
87 glibc 2.12 より前:
88 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
89 .ad b
90 .br
91 ((非標準の) ヘッダファイル \fI<malloc.h>\fP も
92 \fBvalloc\fP() の宣言も公開する。機能検査マクロは不要である。
93 .RE
94 .PD
95 .SH 説明
96 .\" glibc does this:
97 関数 \fBposix_memalign\fP()  は、 \fIsize\fP バイトのメモリを割り当て、割り当てられたメモリのアドレスを \fI*memptr\fP
98 に設定する。 割り当てられたメモリのアドレスは \fIalignment\fP の倍数になっているはずである。 \fIalignment\fP は 2
99 のべき乗で、かつ \fIsizeof(void\ *)\fP の倍数でなければならない。 \fIsize\fP が 0 の場合、
100 \fBposix_memalign\fP()  は NULL か一意なポインタ値を返す。 このポインタ値は、後で \fBfree\fP(3)
101 に問題なく渡すことができる。
102
103 .\" The behavior of memalign() for size==0 is as for posix_memalign()
104 .\" but no standards govern this.
105 廃止された関数である \fBmemalign\fP() は、 \fIsize\fP バイトのメモリを割り当て、
106 割り当てられたメモリへのポインタを返す。 メモリのアドレスは \fIalignment\fP
107 の倍数になっているはずである。 \fIalignment\fP は 2 のべき乗でなければならない。
108
109 関数 \fBaligned_alloc\fP() は \fBmemalign\fP() と同じだが、\fIsize\fP が \fIalignment\fP
110 の倍数でなければならないという追加の制限がある点が異なる。
111
112 廃止された関数である \fBvalloc\fP()  は \fIsize\fP バイトのメモリを割り当て、割り当てられたメモリへのポインタを返す。
113 メモリのアドレスはページサイズの倍数になっているはずである。 これは \fImemalign(sysconf(_SC_PAGESIZE),size)\fP
114 と等価である。
115
116 廃止された関数 \fBpvalloc\fP() は \fBvalloc\fP() と同様だが、
117 割り当てられるサイズがシステムのページサイズの倍数に切り上げられる。
118
119 これらの関数はいずれもメモリのゼロクリアを行わない。
120 .SH 返り値
121 \fBaligned_alloc\fP(), \fBmemalign\fP(), \fBvalloc\fP(), \fBpvalloc\fP() は割り当てられた
122 メモリへのポインタを返す。 割り当てに失敗した場合は NULL を返す。
123
124 \fBposix_memalign\fP()  は成功した場合は 0 を返し、 失敗した場合は次のセクションに記載されたエラー値のいずれかを返す。
125 \fIerrno\fP はセットされないことに注意すること。
126 .SH エラー
127 .TP 
128 \fBEINVAL\fP
129 \fIalignment\fP 引き数が 2 のべき乗でなかったか、 \fIsizeof(void\ *)\fP の倍数でなかった。
130 .TP 
131 \fBENOMEM\fP
132 割り当て要求を満たすのに十分なメモリがなかった。
133 .SH バージョン
134 関数 \fBmemalign\fP(), \fBvalloc\fP(), \fBpvalloc\fP() は
135 すべての Linux libc ライブラリで使用可能である。
136
137 関数 \fBaligned_alloc\fP() は glibc バージョン 2.16 で追加された。
138
139 関数 \fBposix_fallocate\fP() は glibc 2.1.91 以降で利用可能である。
140 .SH 準拠
141 関数 \fBvalloc\fP() は 3.0BSD で登場した。4.3BSD では廃止されたと記載されており、
142 SUSv2 では過去の名残だと記載されている。 POSIX.1\-2001 には存在しない。
143
144 関数 \fBpvalloc\fP() は GNU による拡張である。
145
146 関数 \fBmemalign\fP() は SunOS 4.1.3 で登場したが、4.4BSD にはない。
147
148 関数 \fBposix_memalign\fP() は POSIX.1d に由来する。
149
150 .\"
151 関数 \fIaligned_alloc\fP() は C11 標準で規定されている。
152 .SS ヘッダ
153 \fBposix_memalign\fP()  の宣言を \fI<stdlib.h>\fP で行うことに関しては、 皆の意見が一致している。
154
155 いくつかのシステムでは、 \fBmemalign\fP()  は \fI<malloc.h>\fP ではなく
156 \fI<stdlib.h>\fP で宣言されている。
157
158 SUSv2 によると、 \fBvalloc\fP() は \fI<stdlib.h>\fP で宣言される。 libc4,5
159 や glibc では \fI<malloc.h>\fP で宣言されており、 さらに適切な機能検査
160 マクロが定義された場合には \fI<stdlib.h>\fP でも宣言される(上記を参照)。
161 .SH 注意
162 多くのシステムでは、アラインメントに関して制限がある。例えば、 ブロックデバイスに対するダイレクト I/O に使用するバッファには
163 アラインメントに関する制限がある。 POSIX では、どんなアラインメントが必要かを知るために
164 \fIpathconf(path,_PC_REC_XFER_ALIGN)\fP コールを規定している。ここで \fBposix_memalign\fP()
165 を使うと、この必要条件を満たすことができる。
166
167 \fBposix_memalign\fP() は \fIalignment\fP が上で詳細に述べた必要条件を満たすか
168 どうかを確かめる。 \fBmemalign\fP() は \fIalignment\fP 引き数が正しいかどうかの
169 確認を行わないかもしれない。
170
171 .\" Other systems allow passing the result of
172 .\" .IR valloc ()
173 .\" to
174 .\" .IR free (3),
175 .\" but not to
176 .\" .IR realloc (3).
177 POSIX では \fBposix_memalign\fP() によって獲得したメモリは \fBfree\fP(3) を
178 使って解放することができる必要がある。 いくつかのシステムでは
179 \fBmemalign\fP() や\fBvalloc\fP() で割り当てられたメモリを再利用する手段が
180 提供されていない(なぜなら \fBfree\fP(3) に渡すことができるのは
181 \fBmalloc\fP(3) から受け取ったポインタだけだが、例えば \fBmemalign\fP() は
182 \fBmalloc\fP(3) を呼び出し、得た値をアラインメントしてしまうからである)。
183 glibc の実装では、 ここに述べた関数のいずれで獲得したメモリも
184 \fBfree\fP(3) で再利用することができる。
185
186 glibc の \fBmalloc\fP(3) は常に 8 バイトにアラインメントされたメモリアドレスを
187 返すので、ここで述べた関数が必要になるのは 8 バイトよりも大きなアラインメント
188 が必要な場合だけである。
189 .SH 関連項目
190 \fBbrk\fP(2), \fBgetpagesize\fP(2), \fBfree\fP(3), \fBmalloc\fP(3)
191 .SH この文書について
192 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
193 である。プロジェクトの説明とバグ報告に関する情報は
194 http://www.kernel.org/doc/man\-pages/ に書かれている。