When you read the program source code, you see the Alloca function every now and then. I didn't care much at first, but I didn't notice it until I saw <<APUE>> today.
Microsoft MSVC offers the _alloca.
Brief description:
- It acts in the same way and functions as malloc, which is memory allocation. However, Alloca is allocated on the stack frame of the current caller's function, not in the heap.
Advantages:
- When the function returns, the memory is freed automatically. No manual release required.
Disadvantages:
- The length of the stack frame is increased, and some systems do not support increasing the stack frame length, so the ALLOCA function cannot be supported.
- If memory is allocated to overflow the stack, the program's behavior is unknown.
Reference:
- Why am alloca not considered good practice?
- Man7.org/linux/man-pages/man3/alloca.3.html
Alloca memory allocation function in C language