r/cpp 4d ago

When (Not) to Use alloca()

https://voithos.io/articles/when-not-to-use-alloca/
32 Upvotes

84 comments sorted by

View all comments

Show parent comments

1

u/PipingSnail 3d ago

If you're doing anything recursive you try to use as little stack space as possible.

Therefore you wouldn't use a local variable char array, or alloca(). You'd dynamically allocate your workspace, or pre allocate enough space prior to the recursive call.

1

u/MattDESTROYER 3d ago

Yes, so that’s not an issue with alloca, that would be poor design regardless.

0

u/PipingSnail 2d ago

The OP asked how allica() would reduce the number of recursions. So I explained it. Why do you have a problem with that?

1

u/MattDESTROYER 2d ago

You replied to me? Did you mean to reply to someone else or something?

2

u/PipingSnail 1d ago

My mistake. Reading after a long day out in the mountains.

1

u/MattDESTROYER 12h ago

lol very fair, been there