 | | Like malloc, alloca returns a pointer to size bytes of memory, or a null pointer if the memory is unavailable. However, unlike malloc, which allocates the memory from the program's data segment, alloca allocates it from the program's stack segment. Thus, when the current function returns, the memory is automatically freed by being popped off the stack. This simplifies bookkeeping for programs that allocate large amounts of memory in numerous places. Unfortunately, it is also a portability nightmare. The implementation of alloca is very machine-, compiler-, and, most of all, system-dependent. Some hardware architectures cannot implement it all. For this reason, alloca should never be used by a program that must be portable to many different systems. | |
|