.\" Copyright (c) 2001 by John Levon .\" Based in part on GNU libc documentation. .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" 2001-10-11, 2003-08-22, aeb, added some details .\" 2012-03-23, Michael Kerrisk .\" Document pvalloc() and aligned_alloc() .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2001 Akihiro MOTOKI .\" all rights reserved. .\" Translated 2001-11-05, Akihiro MOTOKI .\" Updated 2003-09-05, Akihiro MOTOKI, catch up to v1.60 .\" Updated 2005-11-19, Akihiro MOTOKI .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24 .\" Updated 2012-05-01, Akihiro MOTOKI .\" Updated 2012-05-08, Akihiro MOTOKI .\" Updated 2013-03-26, Akihiro MOTOKI .\" Updated 2013-07-22, Akihiro MOTOKI .\" .TH POSIX_MEMALIGN 3 2020\-12\-21 GNU "Linux Programmer's Manual" .SH 名前 posix_memalign, aligned_alloc, memalign, valloc, pvalloc \- アラインメント されたメモリーの割り当てを行う .SH 書式 .nf \fB#include \fP .PP \fBint posix_memalign(void **\fP\fImemptr\fP\fB, size_t \fP\fIalignment\fP\fB, size_t \fP\fIsize\fP\fB);\fP \fBvoid *aligned_alloc(size_t \fP\fIalignment\fP\fB, size_t \fP\fIsize\fP\fB);\fP \fBvoid *valloc(size_t \fP\fIsize\fP\fB);\fP \fB#include \fP .PP \fBvoid *memalign(size_t \fP\fIalignment\fP\fB, size_t \fP\fIsize\fP\fB);\fP \fBvoid *pvalloc(size_t \fP\fIsize\fP\fB);\fP .fi .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP .ad l \fBposix_memalign\fP(): _POSIX_C_SOURCE\ >=\ 200112L .PP \fBaligned_alloc\fP(): _ISOC11_SOURCE .PP \fBvalloc\fP(): .br .PD 0 .RS 4 .TP 4 glibc 2.12 以降: .nf (_XOPEN_SOURCE\ >=\ 500) && !(_POSIX_C_SOURCE\ >=\ 200112L) || /* glibc 2.19 以降: */ _DEFAULT_SOURCE || /* glibc 2.19 以前: */ _SVID_SOURCE || _BSD_SOURCE .br .fi .TP glibc 2.12 より前: .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 .ad b .br ((非標準の) ヘッダーファイル \fI\fP も \fBvalloc\fP() の宣言も公開する。機能検査マクロは不要である。 .RE .PD .SH 説明 .\" glibc does this: The function \fBposix_memalign\fP() allocates \fIsize\fP bytes and places the address of the allocated memory in \fI*memptr\fP. The address of the allocated memory will be a multiple of \fIalignment\fP, which must be a power of two and a multiple of \fIsizeof(void\ *)\fP. This address can later be successfully passed to \fBfree\fP(3). If \fIsize\fP is 0, then the value placed in \fI*memptr\fP is either NULL or a unique pointer value. .PP .\" The behavior of memalign() for size==0 is as for posix_memalign() .\" but no standards govern this. 廃止された関数である \fBmemalign\fP() は、 \fIsize\fP バイトのメモリーを割り当て、 割り当てられたメモリーへのポインターを返す。 メモリーのアドレスは \fIalignment\fP の倍数になっているはずである。 \fIalignment\fP は 2 のべき乗でなければならない。 .PP 関数 \fBaligned_alloc\fP() は \fBmemalign\fP() と同じだが、\fIsize\fP が \fIalignment\fP の倍数でなければならないという追加の制限がある点が異なる。 .PP 廃止された関数である \fBvalloc\fP() は \fIsize\fP バイトのメモリーを割り当て、割り当てられたメモリーへのポインターを返す。 メモリーのアドレスはページサイズの倍数になっているはずである。 これは \fImemalign(sysconf(_SC_PAGESIZE),size)\fP と等価である。 .PP 廃止された関数 \fBpvalloc\fP() は \fBvalloc\fP() と同様だが、 割り当てられるサイズがシステムのページサイズの倍数に切り上げられる。 .PP これらの関数はいずれもメモリーのゼロクリアを行わない。 .SH 返り値 \fBaligned_alloc\fP(), \fBmemalign\fP(), \fBvalloc\fP(), and \fBpvalloc\fP() return a pointer to the allocated memory on success. On error, NULL is returned, and \fIerrno\fP is set to indicate the cause of the error. .PP .\" http://austingroupbugs.net/view.php?id=520 \fBposix_memalign\fP() returns zero on success, or one of the error values listed in the next section on failure. The value of \fIerrno\fP is not set. On Linux (and other systems), \fBposix_memalign\fP() does not modify \fImemptr\fP on failure. A requirement standardizing this behavior was added in POSIX.1\-2008 TC2. .SH エラー .TP \fBEINVAL\fP \fIalignment\fP 引数が 2 のべき乗でなかったか、 \fIsizeof(void\ *)\fP の倍数でなかった。 .TP \fBENOMEM\fP 割り当て要求を満たすのに十分なメモリーがなかった。 .SH バージョン 関数 \fBmemalign\fP(), \fBvalloc\fP(), \fBpvalloc\fP() は少なくとも glibc 2.0 以降で使用可能である。 .PP 関数 \fBaligned_alloc\fP() は glibc バージョン 2.16 で追加された。 .PP 関数 \fBposix_fallocate\fP() は glibc 2.1.91 以降で利用可能である。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .TS allbox; lb lb lb l l l. インターフェース 属性 値 T{ \fBaligned_alloc\fP(), .br \fBmemalign\fP(), .br \fBposix_memalign\fP() T} Thread safety MT\-Safe T{ \fBvalloc\fP(), .br \fBpvalloc\fP() T} Thread safety MT\-Unsafe init .TE .sp 1 .SH 準拠 関数 \fBvalloc\fP() は 3.0BSD で登場した。4.3BSD では廃止されたと記載されており、 SUSv2 では過去の名残だと記載されている。 POSIX.1 には存在しない。 .PP 関数 \fBpvalloc\fP() は GNU による拡張である。 .PP 関数 \fBmemalign\fP() は SunOS 4.1.3 で登場したが、4.4BSD にはない。 .PP 関数 \fBposix_memalign\fP() は POSIX.1d に由来し、 POSIX.1\-2001 と POSIX.1\-2008 で規定されている。 .PP .\" 関数 \fIaligned_alloc\fP() は C11 標準で規定されている。 .SS ヘッダー \fBposix_memalign\fP() の宣言を \fI\fP で行うことに関しては、 皆の意見が一致している。 .PP いくつかのシステムでは、 \fBmemalign\fP() は \fI\fP ではなく \fI\fP で宣言されている。 .PP .\" Libc4,5 and SUSv2 によると、 \fBvalloc\fP() は \fI\fP で宣言される。 glibc では \fI\fP で宣言されており、 さらに適切な機能検査マクロが定義された場合には \fI\fP でも宣言される(上記を参照)。 .SH 注意 多くのシステムでは、アラインメントに関して制限がある。例えば、 ブロックデバイスに対するダイレクト I/O に使用するバッファーには アラインメントに関する制限がある。 POSIX では、どんなアラインメントが必要かを知るために \fIpathconf(path,_PC_REC_XFER_ALIGN)\fP コールを規定している。ここで \fBposix_memalign\fP() を使うと、この必要条件を満たすことができる。 .PP \fBposix_memalign\fP() は \fIalignment\fP が上で詳細に述べた必要条件を満たすか どうかを確かめる。 \fBmemalign\fP() は \fIalignment\fP 引数が正しいかどうかの 確認を行わないかもしれない。 .PP .\" Other systems allow passing the result of .\" .IR valloc () .\" to .\" .IR free (3), .\" but not to .\" .IR realloc (3). POSIX では \fBposix_memalign\fP() によって獲得したメモリーは \fBfree\fP(3) を 使って解放することができる必要がある。 いくつかのシステムでは \fBmemalign\fP() や\fBvalloc\fP() で割り当てられたメモリーを再利用する手段が 提供されていない(なぜなら \fBfree\fP(3) に渡すことができるのは \fBmalloc\fP(3) から受け取ったポインターだけだが、例えば \fBmemalign\fP() は \fBmalloc\fP(3) を呼び出し、得た値をアラインメントしてしまうからである)。 glibc の実装では、 ここに述べた関数のいずれで獲得したメモリーも \fBfree\fP(3) で再利用することができる。 .PP glibc の \fBmalloc\fP(3) は常に 8 バイトにアラインメントされたメモリーアドレスを 返すので、ここで述べた関数が必要になるのは 8 バイトよりも大きなアラインメント が必要な場合だけである。 .SH 関連項目 \fBbrk\fP(2), \fBgetpagesize\fP(2), \fBfree\fP(3), \fBmalloc\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。