alloca()
allocates memory on the stack rather than on the heap, as in the case of malloc()
. So, when I return from the routine the memory is freed.
All of the other answers are correct. However, if the thing you want to alloc using alloca()
is reasonably small, I think that it's a good technique that's faster and more convenient than using malloc()
or otherwise.
In other words, alloca( 0x00ffffff )
is dangerous and likely to cause overflow, exactly as much as char hugeArray[ 0x00ffffff ];
is. Be cautious and reasonable and you'll be fine.