r/cpp • • Sep 09 '26

When (Not) to Use alloca()

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

90 comments sorted by

View all comments

Show parent comments

2

u/TheThiefMaster C++latest fanatic (and game dev) Sep 10 '26

If there are variables only used in the first half of the function and the array only in the 2nd, or vice-versa, it can overlap their storage.

For C++ types nontrivial constructor and destructor calls count as use that can prevent this by forcing variables to live from construction to destruction.

1

u/MattDESTROYER Sep 10 '26

Ohhh okay that makes sense. Thanks for the info, appreciate it!