Odin: A C-Inspired Language Embracing Modern Best Practices

2025-05-13
Odin:  A C-Inspired Language Embracing Modern Best Practices

The author, drawing on experience building a game engine in C, highlights Odin's incorporation of several C best practices. These include custom allocators (with built-in support in Odin's core libraries), temporary allocators for frame-based memory management, tracking allocators for leak detection, zero initialization, designated initializers, and cache-friendly programming via SoA support. Odin achieves this while maintaining the simplicity of C, adding modern features like generics and overloading. The author emphasizes that while Odin's features are highly beneficial for those with a similar C background, it's also approachable for those unfamiliar with these concepts, suggesting their book as an introductory resource.

Read more
Development

Odin Arena Allocators and Dynamic Arrays: Hidden Pitfalls

2025-04-13
Odin Arena Allocators and Dynamic Arrays: Hidden Pitfalls

Using arena allocators with dynamic arrays in Odin presents subtle pitfalls. Arenas efficiently manage allocations with the same lifetime, deallocating everything at once. However, dynamic arrays' growth mechanism leaves old memory blocks unfreed when using an arena allocator, leading to wasted memory. The article explains why: arena allocators don't support individual deallocations, and dynamic array growth creates a 'graveyard' of old blocks. Solutions include using the default allocator, pre-allocating maximum size, or employing a virtual growing arena. While the virtual growing arena prevents memory block movement, it's not immune to potential waste. The article concludes that if memory usage is highly dynamic, avoiding arena allocators is advisable.

Read more