Allocate Memory dynamically on stack

Stack dynamic allocation with _alloca(),
What pros and cons one see while using it, as it takes memory from stack.
I have compiled one article for it :-

Though need more suggestion on above part to make it more better.
Last edited on
closed account (zb0S216C)
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.

Is there any case where alloca will outperform new/malloc/calloc.
Lets say in terms of performance.
closed account (zb0S216C)
Well, malloc( ) causes heavy fragmentation. Try reading this link: . This will give you some insight on _alloca( ).

nice article.

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.
Topic archived. No new replies allowed.