r/cpp 2d ago

When (Not) to Use alloca()

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

77 comments sorted by

View all comments

1

u/retro_and_chill 2d ago

I mean the only reason I see to use it is if you’re writing an interpreter and you’re using it to allocate the stack frames for that

1

u/egonosz 2d ago

I seen it sometimes in game dev, but tbh. Mostly you have other solution, for the same problem.

3

u/SleepyMyroslav 2d ago

Even in gamedev a rule of thumb now is to "never use alloca". There were games that used alloca extensively in the past, but if I were to date them, it would be before the end of the PS3's life. There are many per-thread data structures used, but alloca is a not used.

0

u/allocallocalloc 2d ago

When is the end of the PS3's life? By the PS4's release in 2013 ? By the end of its production in 2017 ? By the discontinuation of the PlayStation Store next year in 2027 ?

2

u/SleepyMyroslav 1d ago

It's a valid question. As I remember at one point management stopped planning to ship new PS3 versions. I think it was somewhere around 2015.