Re:using stack...
Posted: Wed Mar 24, 2004 3:41 pm
Actually, alloca() is not just a stack probe. It's a memory allocator function, which basicly acts like malloc(), but allocates from stack, so that the memory allocated with alloca() is automatically deallocated when the stack frame (function) returns.
Basicly, it might be useful when it's necessary to allocate some dynamic amount of memory (say a varying length buffer) but malloc() can't be used -- say, not implemented, or there's possibility of a longjmp() without ever calling free().
From linux alloca man-page:
Basicly, it might be useful when it's necessary to allocate some dynamic amount of memory (say a varying length buffer) but malloc() can't be used -- say, not implemented, or there's possibility of a longjmp() without ever calling free().
From linux alloca man-page:
Gcc normally implements alloca() with inlined code, unless you use -fno-builtin, so it can be faster than using malloc() as it's basicly just a question of adjusting the stack-pointer and making sure rest of the code doesn't go mad. Cygwin uses alloca() as a kludge-fix on Windows, but the function itself is not Windows-specific.CONFORMING TO
There is evidence that the alloca function appeared in 32v, pwb, pwb.2,
3bsd, and 4bsd. There is a man page for it in BSD 4.3. Linux uses the
GNU version. This function is not in POSIX or SUSv3.