Move Allocator patterns from std.heap to std.alloc #22272
+1,228
−1,181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Because allocations are such a core pattern within Zig, the various Allocators deserve a clear namespace of their own. Additionally a number of the various allocators may be misleading or confusing within the heap name namespace, e.g.
FixedBufferAllocator
where most of the examples and uses use stack based memory, and not heap.Additionally moving the various Allocators from heap into std.alloc also improves the stdlib namespace. Where
std.heap.ArenaAllocator
is nowstd.alloc.Arena
There's still a large number of places through out that still use
std.heap
instead of the new namespace. Aliases are provided within std.heap for all of the moved Allocators, as I wanted to solicit some feedback on the PR and approach.Most uses within alloc have been updated, notably none of the uses in GeneralPurposeAllocator, which uses
@import("std")
instead of@import("../std.zig")
. I didn't want to change this without knowing why.Also of note on line 1473 of gpa, it appears to test the GPA from standard lib, rather than the current version within the file. I changed this to test the current implementation from the file because there were no comments explaining why, which seemed like a bug.
I assume it's likely I'm missing some other nuance, e.g. I moved and reduced the scope of next_mmap_addr_hint because I couldn't find any other uses.