‹ BackHN Continuity

Thread

What Zig felt like, coming from Rust

282 points · 351 comments · ksec

  1. ozgrakkurt · · focus · HN ↗
    Would recommend learning how to use arena allocation. You would have patterns like:

    fn run_query(alloc) {

       arena = init_arena(alloc);
    
       defer arena.deinit();
    
    }
    1. simonask · · focus · HN ↗
      Step zero of using arena allocation is to build realistic benchmarks so you can measure if it's worth the trouble in the first place. Standard allocators are incredibly good these days, and even plugging in mimalloc or jemalloc will be much less work, and much less error prone.
      1. slopinthebag · · focus · HN ↗
        i think the reason is more that arena's let you manage lifetimes in groups instead of pointer chasing. if you have to manually manage memory, it's eaiser to manage a small number of arena objects instead of a large number of individual objects.

        eg <a href="https:&#x2F;&#x2F;www.dgtlgrove.com&#x2F;p&#x2F;untangling-lifetimes-the-arena-allocator" rel="nofollow">https:&#x2F;&#x2F;www.dgtlgrove.com&#x2F;p&#x2F;untangling-lifetimes-the-arena-a...

        that being said, it&#x27;s even easier to not manage any lifetimes at all :)

        although i suppose some will say that you still manage lifetimes in rust, you just have full support from the compiler to make sure you do it right. that seems better to me than relying on simplification to ensure you don&#x27;t make mistakes.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.