As far as I know, alloca()
dynamically allocates memory in stack, not heap, and releases memory on its own when it returns from routine
Then shouldn't it be recommended because it's safer because it doesn't have to be free like malloc()
?
But why can't I use it?
If you look at the linux man page
RETURN VALUE The alloca() function returns a pointer to the beginning of the allocated space. If the allocation causes stack overflow, program behaviour is undefined.
That's what it says. It says it's a problem if there's a stack overflow, and it doesn't say not to use it.
It doesn't say never to use it It's a function that doesn't matter if you don't assign a big value It was a function that I used often in my project.
© 2024 OneMinuteCode. All rights reserved.