logoalt Hacker News

IggleSnigglelast Friday at 2:01 PM3 repliesview on HN

Caveat emptor, I don't write Zig but followed its development closely for awhile. A core design element of zig is that you shouldn't be stuck with one particular memory model. Zig encourages passing an allocator context around, where those allocators conform to a standardized interface. That means you could pass in different allocators with different performance characteristics at runtime.

But yes, there is a default allocator, std.heap.page_allocator


Replies

SkiFire13last Friday at 3:48 PM

> you shouldn't be stuck with one particular memory model

Nit: an allocator is not a "memory model", and I very much want the memory model to not change under my feet.

throwawaymathslast Friday at 3:55 PM

> Zig encourages passing an allocator context around, where those allocators conform to a standardized interface.

in libraries. if youre just writing a final product it's totally fine to pick one and use it everywhere.

> std.heap.page_allocator

strongly disrecommend using this allocator as "default", it will take a trip to kernelland on each allocation.

hansvmlast Friday at 3:12 PM

std.heap.smp_allocator

You should basically only use the page allocator if you're writing another allocator.