Sep 21, 2011 at 6:15pm UTC
Last edited on
Sep 21, 2011 at 6:17pm UTC
Sep 21, 2011 at 6:24pm UTC
Any object that is pushed onto the stack is dynamically allocated anyway. Apparently,
_alloca( ) has the potential to put the program's stack in the overflow state. Consider using malloc( ), calloc( ), or new/new. In addition, _alloca( ) is considered to be quite buggy according to the experts on Stack Overflow.
Sep 21, 2011 at 6:31pm UTC
Is there any case where alloca will outperform new/malloc/calloc.
Lets say in terms of performance.
Sep 21, 2011 at 6:52pm UTC
malloc( ) causes heavy fragmentation. Try reading this link: http://compilers.iecc.com/comparch/article/91-12-079 . This will give you some insight on _alloca( ).
Sep 28, 2011 at 9:42am UTC
i got following from it
Disadvantage of using alloca :-
There are a variety of problems, none insurmountable:
* It requires compiler support.
* Every routine that has |alloca()| requires both a frame pointer
and a stack pointer.
* The compiler has to get right things like
f (alloca(10), alloca(10));
The naive implementation does something like: allocate 10 bytes,
push the address, allocate 10 bytes, push the address. The correct
behavior is allocate 10, allocate 10, push, push.
Fixing these problems is a ``small matter of programming'', that
complicates several things, with the corresponding problem of more bugs.