Hi folks, I’m used to languages with garbage collectors, so I haven’t had much experience working directly with memory allocation like Zig requires with allocators. I’d like to understand more about how allocators work, such as why there are so many different kinds, and how/when to choose one or another.
Can anyone recommend some good resources or content that could help me build a clearer understanding of allocators?
The zig doc section that @Sze linked needs updating.
While GeneralPurposeAllocator still exists, it’s now an alias to DebugAllocator and has had some internal changes as it’s now only meant for debug builds, for release builds there is smp_allocator which is thread safe and about as fast as glibc malloc, which is very impressive. Everything before GeneralPurposeAllocator is still valid
I’ve found this blog post very helpful to get a grasp of how many allocator implementations out there work at a basic level. It introduces a lot of terms and concepts that you will encounter quite frequently when dealing with allocators. It’s not specific to Zig though.