OSDN Git Service

bd23ea97d320f38871942ccd0e45fce8f3aaeb7a
[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 .\" 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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" License.
24 .\"
25 .\" 2001-10-11, 2003-08-22, aeb, added some details
26 .\"
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
33 .\"
34 .\"WORD:        obsolete        廃止された
35 .\"WORD:        a multiple of   〜の倍数
36 .\"WORD:        a power of two  2 のべき乗
37 .\"
38 .TH POSIX_MEMALIGN 3  2010-09-20 "GNU" "Linux Programmer's Manual"
39 .\"O .SH NAME
40 .SH 名前
41 .\"O posix_memalign, memalign, valloc \- Allocate aligned memory
42 posix_memalign, memalign, valloc \- アラインメントされたメモリの割り当てを行う
43 .\"O .SH SYNOPSIS
44 .SH 書式
45 .nf
46 .B #include <stdlib.h>
47 .sp
48 .BI "int posix_memalign(void **" memptr ", size_t " alignment ", size_t " size );
49 .sp
50 .B #include <malloc.h>
51 .sp
52 .BI "void *valloc(size_t " size );
53 .BI "void *memalign(size_t " boundary ", size_t " size );
54 .fi
55 .sp
56 .in -4n
57 .\"O Feature Test Macro Requirements for glibc (see
58 .\"O .BR feature_test_macros (7)):
59 glibc 向けの機能検査マクロの要件
60 .RB ( feature_test_macros (7)
61 参照):
62 .in
63 .sp
64 .ad l
65 .BR posix_memalign ():
66 .RS 4
67 _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
68 .RE
69 .sp
70 .BR valloc ():
71 .br
72 .PD 0
73 .RS 4
74 .TP 4
75 .\"O Since glibc 2.12:
76 glibc 2.12 以降:
77 .nf
78 _BSD_SOURCE ||
79     (_XOPEN_SOURCE\ >=\ 500 ||
80         _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
81     !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
82 .br
83 .fi
84 .TP
85 .\"O Before glibc 2.12:
86 glibc 2.12 より前:
87 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
88 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
89 .RE
90 .PD
91 .ad b
92 .\"O .SH DESCRIPTION
93 .SH 説明
94 .\"O The function
95 .\"O .BR posix_memalign ()
96 .\"O allocates
97 .\"O .I size
98 .\"O bytes and places the address of the allocated memory in
99 .\"O .IR "*memptr" .
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 *)".
104 関数
105 .BR posix_memalign ()
106 は、
107 .I size
108 バイトのメモリを割り当て、割り当てられたメモリのアドレスを
109 .I "*memptr"
110 に設定する。
111 割り当てられたメモリのアドレスは
112 .I "alignment"
113 の倍数になっているはずである。
114 .I "alignment"
115 は 2 のべき乗で、かつ
116 .IR "sizeof(void *)"
117 の倍数でなければならない。
118 .\"O If
119 .\"O .I size
120 .\"O is 0, then
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
125 .\"O .BR free (3).
126 .I size
127 が 0 の場合、
128 .BR posix_memalign ()
129 は NULL か一意なポインタ値を返す。
130 このポインタ値は、後で
131 .BR free (3)
132 に問題なく渡すことができる。
133
134 .\"O The obsolete function
135 .\"O .BR memalign ()
136 .\"O allocates
137 .\"O .I size
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.
142 廃止された関数である
143 .BR memalign ()
144 は、
145 .I size
146 バイトのメモリを割り当て、割り当てられたメモリへのポインタを返す。
147 メモリのアドレスは
148 .I "boundary"
149 の倍数になっているはずである。
150 .I "boundary"
151 は 2 のべき乗でなければならない。
152 .\" The behavior of memalign() for size==0 is as for posix_memalign()
153 .\" but no standards govern this.
154
155 .\"O The obsolete function
156 .\"O .BR valloc ()
157 .\"O allocates
158 .\"O .I size
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)" .
163 廃止された関数である
164 .BR valloc ()
165
166 .I size
167 バイトのメモリを割り当て、割り当てられたメモリへのポインタを返す。
168 メモリのアドレスはページサイズの倍数になっているはずである。
169 これは
170 .I "memalign(sysconf(_SC_PAGESIZE),size)"
171 と等価である。
172
173 .\"O For all three routines, the memory is not zeroed.
174 .\" motoki: be not zeroed ってどういう意味?
175 3 つの関数はいずれもメモリのゼロクリアを行わない。
176 .\"O .SH "RETURN VALUE"
177 .SH 返り値
178 .\"O .BR memalign ()
179 .\"O and
180 .\"O .BR valloc ()
181 .\"O return the pointer to the allocated memory, or NULL if the request fails.
182 .BR memalign ()
183
184 .BR valloc ()
185 は割り当てられたメモリへのポインタを返す。
186 割り当てに失敗した場合は NULL を返す。
187
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.
191 .\"O Note that
192 .\"O .I errno
193 .\"O is not set.
194 .BR posix_memalign ()
195 は成功した場合は 0 を返し、
196 失敗した場合は次のセクションに記載されたエラー値のいずれかを返す。
197 .I errno
198 はセットされないことに注意すること。
199 .\"O .SH "ERRORS"
200 .SH エラー
201 .TP
202 .B EINVAL
203 .\"O The
204 .\"O .I alignment
205 .\"O argument was not a power of two, or was not a multiple of
206 .\"O .IR "sizeof(void *)" .
207 .I alignment
208 引き数が 2 のべき乗でなかったか、
209 .IR "sizeof(void *)"
210 の倍数でなかった。
211 .TP
212 .B ENOMEM
213 .\"O There was insufficient memory to fulfill the allocation request.
214 割り当て要求を満たすのに十分なメモリがなかった。
215 .\"O .SH VERSIONS
216 .SH バージョン
217 .\"O The functions
218 .\"O .BR memalign ()
219 .\"O and
220 .\"O .BR valloc ()
221 .\"O have been available in all Linux libc libraries.
222 .BR memalign ()
223
224 .BR valloc ()
225 はすべての Linux libc ライブラリで使用可能である。
226 .\"O The function
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"
232 .SH 準拠
233 .\"O The function
234 .\"O .BR valloc ()
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.
239 関数
240 .BR valloc ()
241 は 3.0BSD で登場した。4.3BSD では廃止されたと記載されており、
242 SUSv2 では過去の名残だと記載されている。
243 POSIX.1-2001 にはもはや存在しない。
244 .\"O The function
245 .\"O .BR memalign ()
246 .\"O appears in SunOS 4.1.3 but not in 4.4BSD.
247 関数
248 .BR memalign ()
249 は SunOS 4.1.3 で登場したが、4.4BSD にはない。
250 .\"O The function
251 .\"O .BR posix_memalign ()
252 .\"O comes from POSIX.1d.
253 関数
254 .BR posix_memalign ()
255 は POSIX.1d に由来する。
256 .\"O .SS Headers
257 .SS ヘッダ
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 皆の意見が一致している。
264
265 .\"O On some systems
266 .\"O .BR memalign ()
267 .\"O is declared in \fI<stdlib.h>\fP instead of \fI<malloc.h>\fP.
268 いくつかのシステムでは、
269 .BR memalign ()
270 は \fI<malloc.h>\fP ではなく \fI<stdlib.h>\fP で宣言されている。
271
272 .\"O According to SUSv2,
273 .\"O .BR valloc ()
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
277 .\"O (namely, if
278 .\"O .B _GNU_SOURCE
279 .\"O is defined, or
280 .\"O .B _BSD_SOURCE
281 .\"O is defined, or,
282 .\"O for glibc, if
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).
287 SUSv2 によると、
288 .BR valloc ()
289
290 .I <stdlib.h>
291 で宣言される。
292 libc4,5 や glibc では
293 .I <malloc.h>
294 で宣言されており、
295 さらに
296 .I <stdlib.h>
297 でも宣言されることもある
298 (具体的には以下のいずれかの場合:
299 .B _GNU_SOURCE
300 が定義されている、
301 .B _BSD_SOURCE
302 が定義されている、
303 glibc で
304 .B _XOPEN_SOURCE_EXTENDED
305 が定義されている、
306 glibc で
307 .B _XOPEN_SOURCE
308 が 500 より小さくない値に定義されている)。
309 .\"O .SH NOTES
310 .SH 注意
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.
316 .\"O Now one can use
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 を使うと、この必要条件を満たすことができる。
327
328 .\"O .BR posix_memalign ()
329 .\"O verifies that
330 .\"O .I alignment
331 .\"O matches the requirements detailed above.
332 .BR posix_memalign ()
333
334 .I alignment
335 が上で詳細に述べた必要条件を満たすかどうかを確かめる。
336 .\"O .BR memalign ()
337 .\"O may not check that the
338 .\"O .I boundary
339 .\"O argument is correct.
340 .BR memalign ()
341
342 .I boundary
343 引き数が正しいかどうかの確認を行わないかもしれない。
344
345 .\"O POSIX requires that memory obtained from
346 .\"O .BR posix_memalign ()
347 .\"O can be freed using
348 .\"O .BR free (3).
349 POSIX では
350 .BR posix_memalign ()
351 によって獲得したメモリは
352 .BR free (3)
353 を使って解放することができる必要がある。
354 .\"O Some systems provide no way to reclaim memory allocated with
355 .\"O .BR memalign ()
356 .\"O or
357 .\"O .BR valloc ()
358 いくつかのシステムでは
359 .BR memalign ()
360
361 .BR valloc ()
362 で割り当てられたメモリを再利用する手段が提供されていない。
363 .\"O (because one can only pass to
364 .\"O .BR free (3)
365 .\"O a pointer gotten from
366 .\"O .BR malloc (3),
367 .\"O while, for example,
368 .\"O .BR memalign ()
369 .\"O would call
370 .\"O .BR malloc (3)
371 .\"O and then align the obtained value).
372 .\" motoki: while の前後のつながりはこれでいい?
373 (なぜなら
374 .BR free (3)
375 に渡すことができるのは
376 .BR malloc (3)
377 から受け取ったポインタだけだが、
378 例えば
379 .BR memalign ()
380
381 .BR malloc (3)
382 を呼び出し、得た値をアラインメントしてしまうからである)
383 .\" Other systems allow passing the result of
384 .\" .BR valloc ()
385 .\" to
386 .\" .BR free (3),
387 .\" but not to
388 .\" .BR realloc (3).
389 .\"O The glibc implementation
390 .\"O allows memory obtained from any of these three routines to be
391 .\"O reclaimed with
392 .\"O .BR free (3).
393 glibc の実装では、
394 ここに述べた 3 つの関数のいずれで獲得したメモリも
395 .BR free (3)
396 で再利用することができる。
397
398 .\"O glibc
399 .\"O .BR malloc (3)
400 .\"O always returns 8-byte aligned memory addresses, so these routines are only
401 .\"O needed if you require larger alignment values.
402 glibc の
403 .BR malloc (3)
404 は常に 8 バイトにアラインメントされたメモリアドレスを返すので、
405 ここで述べた関数が必要になるのは
406 8 バイトよりも大きなアラインメントが必要な場合だけである。
407 .\"O .SH "SEE ALSO"
408 .SH 関連項目
409 .BR brk (2),
410 .BR getpagesize (2),
411 .BR free (3),
412 .BR malloc (3)