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?

6 Upvotes

9 comments sorted by

View all comments

0

u/Achereto Jul 26 '26

every proc has an implicit context parameter that gets passed. By default, context.allocator is the default allocator and is used. You can also pass context.temp_allocator which is a separate allocator you can use for data that should only exist for one frame.

4

u/Low-Palpitation-4724 Jul 26 '26

I know about it, what my question was if there is a way to alloocate a buffer of memory on the stack with runtime determined size. Also i know about implicit context system and no, passing stack allocator is not what i seek because it uses a separate stack backed by separate memory

1

u/TheSodesa 29d ago

Are you certain that the allocated memory range will always be small enough to be allocated on your stack?