[about alloca vs malloc]

If you allocate with malloc and then accidentally overwrite it, you get a
corrupted heap.
If you allocate with alloca and then accidentally overwrite it, you get a
corrupted stack.

Guess which is easier to notice :-)

Besides, alloca is a GCC builtin (IIRC), so you you don't have to worry
about its implementation (the GCC folks do :). As long as you have the
stack to allocate from, it's as transparent as declaring automatic arrays
with variable length. e.g.

p = alloca( strlen(s) );

is almost the same as

char a[ strlen(s) ], p=a;
/* this is a legal GCC extension */

--
Csaba Ráduly, Software Engineer                     Sophos Anti-Virus
email: [EMAIL PROTECTED]                  http://www.sophos.com
US support: +1 888 SOPHOS 9               UK Support: +44 1235 559933



Reply via email to