Why is the use of alloca() not considered good practice?

前端 未结 22 2802
甜味超标
甜味超标 2020-11-22 03:00

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.

22条回答
  •  不要未来只要你来
    2020-11-22 03:20

    Processes only have a limited amount of stack space available - far less than the amount of memory available to malloc().

    By using alloca() you dramatically increase your chances of getting a Stack Overflow error (if you're lucky, or an inexplicable crash if you're not).

提交回复
热议问题