← Back to context

Comment by jacquesm

4 days ago

I don't know who told you. But it's a lot slower than malloc, and requires you to do a bunch of bookkeeping, which is easy to mess up if you have multiple exits from your function.

> But it's a lot slower than malloc

How would it be slower? Isn't it simply bumping the stack pointer?

alloca is just a couple of instructions to allocate more memory on the stack, it is much faster than malloc for pretty much every reason including locality and the fact that it doesn't have to be freed because it goes away after the current scope.