.\" Copyright (c) 1980, 1991 Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)alloca.3 5.1 (Berkeley) 5/2/91 .\" .\" Converted Mon Nov 29 11:05:55 1993 by Rik Faith .\" Modified Tue Oct 22 23:41:56 1996 by Eric S. Raymond .\" Modified 2002-07-17, aeb .\" 2008-01-24, mtk: .\" Various rewrites and additions (notes on longjmp() and SIGSEGV). .\" Weaken warning against use of alloca() (as per Debian bug 461100). .\" .\" Japanese Version Copyright (c) 1996 Kentaro OGAWA .\" all rights reserved. .\" Translated Sat, 13 Jul 1996 22:44:04 +0900 .\" by Kentaro OGAWA .\" Updated & Modified Tue Oct 16 01:01:48 JST 2001 .\" by Yuichi SATO .\" Updated & Modified Sat Aug 31 04:42:49 JST 2002 by Yuichi SATO .\" .TH ALLOCA 3 2008-01-24 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O alloca \- allocate memory that is automatically freed alloca \- 自動的に解放されるメモリを割り当てる .\"O .SH SYNOPSIS .SH 書式 .B #include .sp .BI "void *alloca(size_t " size ); .\"O .SH DESCRIPTION .SH 説明 .\"O The .\"O .BR alloca () .\"O function allocates .\"O .I size .\"O bytes of space in the stack frame of the caller. .\"O This temporary space is .\"O automatically freed when the function that called .\"O .BR alloca () .\"O returns to its caller. .BR alloca () 関数は、 .I size バイトの領域を呼出元のスタック・フレームに割り付ける。 この一時的な領域は、 .BR alloca () を呼び出した関数が呼出元に返るときに自動的に解放される。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O The .\"O .BR alloca () .\"O function returns a pointer to the beginning of the allocated space. .\"O If the allocation causes stack overflow, program behavior is undefined. .BR alloca () 関数は、割り付けた領域の始まりを指すポインタを返す。 割り付けによってスタックオーバーフローが起った場合の プログラムの動作は定義されていない。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O This function is not in POSIX.1-2001. この関数は POSIX.1-2001 にはない。 .\"O There is evidence that the .\"O .BR alloca () .\"O function appeared in 32V, PWB, PWB.2, 3BSD, and 4BSD. .\"O There is a man page for it in 4.3BSD. .\"O Linux uses the GNU version. .\"O This function is not in POSIX.1-2001. 32V, PWB, PWB.2, 3BSD, 4BSD に .BR alloca () 関数が登場した証拠がある。 4.3BSD には、マニュアルページがある。 Linux は、GNU 版を使っている。 この関数は POSIX.1-2001 にはない。 .\"O .SH NOTES .SH 注意 .\"O The .\"O .BR alloca () .\"O function is machine- and compiler-dependent. .BR alloca () 関数は、機種とコンパイラに依存する。 .\"O For certain applications, .\"O its use can improve efficiency compared to the use of .\"O .BR malloc (3) .\"O plus .\"O .BR free (3). .\"O In certain cases, .\"O it can also simplify memory deallocation in applications that use .\"O .BR longjmp (3) .\"O or .\"O .BR siglongjmp (3). .\"O Otherwise, its use is discouraged. 特定のアプリケーションでは、この関数を使うと .BR malloc (3) と .BR free (3) を組み合わせて使った場合に比べて効率を改善することができる。 特定の場合では、この関数を使うことで、 .BR longjmp (3) や .BR siglongjmp (3) を使うアプリケーションでのメモリの開放を簡単にすることができる。 それ以外の場合では、この関数の使用は推奨されない。 .\"O Because the space allocated by .\"O .BR alloca () .\"O is allocated within the stack frame, .\"O that space is automatically freed if the function return .\"O is jumped over by a call to .\"O .BR longjmp (3) .\"O or .\"O .BR siglongjmp (3). .BR alloca () により割り当てられる空間はスタックフレームから割り当てらるので、 関数の戻り先が .BR longjmp (3) や .BR siglongjmp (3) の呼び出しによりジャンプした場合には、 割り当てられた空間は自動的に解放される。 .\"O Do not attempt to .\"O .BR free (3) .\"O space allocated by .\"O .BR alloca ()! .BR alloca () で割り当てられた空間を .BR free (3) しようとすることのないように! .\"O .SS Notes on the GNU Version .SH 注意 .SS GNU 版についての注意 .\"O Normally, .\"O .BR gcc (1) .\"O translates calls to .\"O .BR alloca () .\"O with inlined code. .\"O This is not done when either the .\"O .IR "\-ansi" , .\"O .IR "\-std=c89" , .\"O .IR "\-std=c99" , .\"O or the .\"O .IR "\-fno\-builtin" .\"O option is given .\"O (and the header .\"O .I .\"O is not included). .\"O But beware! .\"O By default the glibc version of .\"O .I .\"O includes .\"O .I .\"O and that contains the line: .\"O .nf .\"O .\"O #define alloca(size) __builtin_alloca (size) .\"O .\"O .fi .\"O with messy consequences if one has a private version of this function. 通常 .BR gcc (1) は .BR alloca () の呼び出しをインラインコードに変換する。 .IR "\-ansi" , .IR "\-std=c89" , .IR "\-std=c99" , .IR "\-fno\-builtin" のいずれかのオプションが指定された場合、この変換は行われない (また .I のインクルードも行われない)。 だだし、デフォルトでは glibc 版の .I は .I をインクルードしており、これには以下の行が含まれているので注意すること。 .nf #define alloca(size) __builtin_alloca (size) .fi 独自版の __builtin_alloca (size) 関数があると厄介な結果になる。 .LP .\"O The fact that the code is inlined means that it is impossible .\"O to take the address of this function, or to change its behavior .\"O by linking with a different library. このコードはインライン化されているので、 この関数のアドレスを取得したり、 他のライブラリをリンクして動作を変更することはできない。 .LP .\"O The inlined code often consists of a single instruction adjusting .\"O the stack pointer, and does not check for stack overflow. .\"O Thus, there is no NULL error return. 通常このインラインコードはスタックポインタを移動する 1 つの命令 (instruction) から構成されており、 スタックオーバーフローをチェックしない。 よって NULL エラーが返されることはない。 .\"O .SH BUGS .SH バグ .\"O There is no error indication if the stack frame cannot be extended. .\"O (However, after a failed allocation, the program is likely to receive a .\"O .B SIGSEGV .\"O signal if it attempts to access the unallocated space.) スタックフレームが拡張できなかった場合、エラー通知は行われない。 (しかしながら、割り当てに失敗した後で、プログラムが割り当てられなかった 空間にアクセスしようとした場合に .B SIGSEGV シグナルを受信することだろう。) .\"O On many systems .\"O .BR alloca () .\"O cannot be used inside the list of arguments of a function call, because .\"O the stack space reserved by .\"O .BR alloca () .\"O would appear on the stack in the middle of the space for the .\"O function arguments. 多くのシステムにおいて、関数コールの引き数のリスト内では .BR alloca () が使えない。 これは、 .BR alloca () によって予約されるスタック領域が、 関数引き数に使われるスタック領域の中に現れてしまうためである。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR brk (2), .BR longjmp (3), .BR malloc (3)