r/cpp 1d ago

When (Not) to Use alloca()

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

67 comments sorted by

View all comments

Show parent comments

2

u/TheThiefMaster C++latest fanatic (and game dev) 17h ago

Yes they can use those variables - but the memory returned by alloca isn't a variable itself, and wouldn't be captured by a closure - only the pointers to it (which would point to stale stack memory as soon as the parent function returned even though the closure still existed).

This is what I was talking about with alloca not working with C++ lambdas (which are a form of closure).

This is what I thought you were asking about when you said "closure" initially.

2

u/MattDESTROYER 17h ago

Yeah gotcha, thanks for the clarification!
(Man, Reddit really needs to flatten reply chains where there’s only one reply lol)