Buy the book!
|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
alloca supports a kind of half-dynamic allocation in
which blocks are allocated dynamically but freed automatically.
Allocating a block with
alloca is an explicit action; you can
allocate as many blocks as you wish, and compute the size at run time. But
all the blocks are freed when you exit the function that
called from, just as if they were automatic variables declared in that
function. There is no way to free the space explicitly.
The prototype for
alloca is in `stdlib.h'. This function is
a BSD extension.
allocais the address of a block of size bytes of memory, allocated in the stack frame of the calling function.
Do not use
alloca inside the arguments of a function call--you
will get unpredictable results, because the stack space for the
alloca would appear on the stack in the middle of the space for
the function arguments. An example of what to avoid is
alloca (4), y).
Example of using
220.127.116.11 Advantages of
Reasons to use
18.104.22.168 Disadvantages of
Reasons to avoid
22.214.171.124 GNU C Variable-Size Arrays Only in GNU C, here is an alternative method of allocating dynamically and freeing automatically.
|webmaster||delorie software privacy|
|Copyright © 2003 by The Free Software Foundation||Updated Jun 2003|