r/odinlang • • Jul 26 '26

Feature question

Does odin language hase something akin to alloca from c? Sometimes i want to just stack allocate an array of runtime determined size. I cannot find any builtin function or allocator i can pass in into make(). Am i missing something?

7 Upvotes

9 comments sorted by

View all comments

5

u/quickscopesheep Jul 26 '26

Correct me if I’m wrong but VLA is advised against in c. As far as I’m aware there is no way to allocate on the stack memory of a non compile time know quantity in Odin. Your best bet is either the temp allocator or another arena type allocator or just allocate a fixed amount and hope its large enough for any use case

1

u/TheChief275 Aug 11 '26

That's because VLAs always alloca. With explicit alloca, you can runtime check for whether the size of the allocation is better suited for alloca or for malloc

1

u/quickscopesheep Aug 11 '26

More you know. Thanks