Comment by MangoToupe

15 hours ago

Odin claims to be pragmatic (what language doesn't lol) but "All procedures that returned allocated memory will require an explicit allocator to be passed". Charitably, is this aimed at c/zig heads?

> All procedures that returned allocated memory will require an explicit allocator to be passed

All procedures in core/os. Odin isn't removing the allocator from implicit context in the rest of its APIs.

I'm guessing it's aimed at game development since Vulkan has a similar pattern in every function call (although optional, the driver does it's own allocation if you pass null).

  • That's a pretty heavyweight pattern. Wouldn't dynamic scope be better?

    • As another commenter wrote "how do you allocate memory without an allocator?"

      Even `malloc` has overhead.

      > Wouldn't dynamic scope be better?

      Dynamic scope would likely be heavier than what Odin has, since it'd require the language itself to keep track of this - and to an extent Odin does do this already with `context.allocator`, it just provides an escape hatch when you need something allocated in a specific way.

      Then again, Odin is not a high level scripting language like Python or JavaScript - even the most bloated abstractions in Odin will run like smooth butter compared to those languages. When comparing to C/Rust/Zig, yeah fair, we'll need to bring out the benchmarks.

      4 replies →

How do you allocate memory without an allocator?

  • The usual thing for languages is to provide a global allocator. That's what C's malloc is doing for example. We're not asked to specify the allocator, it's provided by the language runtime so it's implied everywhere.

    In standalone C, or Rust's no_std, there is no allocator provided, but most people aren't writing bare metal software.

    • That creates problems when you need to use multiple allocators. IMO allowing an allocator to be specified is a superior design.