GPA is Dead. Long Live the Debug Allocator

I was doing some studying on the General Purpose Allocator (and maybe even found a bug) when i found this Gem in some commits from yesterday:

I think this is a great move. While the GPA has been good for handling “General” cases (i.e unpredictable memory usage patterns), the reall sell of the GPA is it’s Debugging features: stack trace, leak detection, etc.

10 Likes


:p

6 Likes

What is Smp?

The name comes from Symmetric multiprocessing - Wikipedia

It’s a thread safe allocator intended to be faster than DebugAllocator (which also supports a thread safe mode)

4 Likes

There is an entry in the devlog about it: Devlog ⚡ Zig Programming Language and a discussion on lobste.rs: No-Libc Zig Now Outperforms Glibc Zig | Lobsters.

1 Like

So… what is THE non-debug allocator, now that name / functionality has changed?

There isn’t one yet. See the “How to use it” and “Follow-up issues” sections of

3 Likes

Hello!

So is my understanding correct that the new SmpAllocator is now intended to be the default production-grade (release mode) allocator?

The reason I ask is because it looks like it’s thread-safe by default, but for example if I’m working on a traditional single-threaded game loop maybe I would rather opt-in to enable thread-safety? In the Zig docs I know there is a ThreadedAllocator that can wrap child allocators to provide the necessary synchronization which I liked the opt-in choice.

This isn’t intended to be a nitpick or critical but I’m just trying to get prepared for what to use since the GPA is no longer recommended to actually be general purpose and should be only used in Debug builds.

Thanks y’all.

From here:

std.heap.SmpAllocator fills the niche of -OReleaseFast -fno-single-threaded

There’s currently no allocator tailored towards -OReleaseFast -fsingle-threaded, but I would assume such an allocator would be welcomed.

(see also my last comment about follow up issues)

2 Likes