| tajendra (44) | |
|
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 :- http://tajendrasengar.blogspot.com/2010/02/how-to-allocate-memory-dynamically-on.html Though need more suggestion on above part to make it more better. | |
|
Last edited on
|
|
| Framework (3116) | |
|
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. Wazzak | |
|
|
|
| tajendra (44) | |
|
Is there any case where alloca will outperform new/malloc/calloc. Lets say in terms of performance. | |
|
|
|
| Framework (3116) | |
|
Well, 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( ). Wazzak | |
|
|
|
| tajendra (44) | |
|
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. | |
|
|
|