Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

std.ArrayHashMap: add reinit method and other housekeeping, including the move towards "unmanaged" containers #22087

Merged
merged 4 commits into from
Nov 28, 2024

Conversation

andrewrk
Copy link
Member

std.ArrayHashMap is now deprecated and aliased to std.ArrayHashMapWithAllocator.

To upgrade, switch to ArrayHashMapUnmanaged which will entail updating callsites to pass an allocator to methods that need one. After Zig 0.14.0 is released, std.ArrayHashMapWithAllocator will be removed and std.ArrayHashMapUnmanaged will be a deprecated alias of ArrayHashMap. After Zig 0.15.0 is released, the deprecated alias ArrayHashMapUnmanaged will be removed.

This move comes from unanimous agreement among veteran Zig users who have converged on the "unmanaged" container variants. They act as better building blocks, avoiding storing the same data redundantly, and the presence/absence of the allocator parameter dovetails nicely with the reserve capacity / reserved insertion pattern.

@andrewrk andrewrk added standard library This issue involves writing Zig code for the standard library. release notes This PR should be mentioned in the release notes. labels Nov 27, 2024
@mlugg
Copy link
Member

mlugg commented Nov 27, 2024

I know ArrayList is a little more dicey since we want to rename it, but this PR could also do HashMap, and any others I'm forgetting about.

@linusg
Copy link
Contributor

linusg commented Nov 28, 2024

What's the rationale for the last commit? My understanding is that "gpa" stands for "general purpose allocator", a specific implementation that can provide the allocator interface. Similarly "arena" is a specific allocator implementation. Using these to refer to arbitrary allocator instances seems unintuitive.

@leroycep
Copy link
Contributor

My understanding of the gpa convention is that it more refers to a class of implementations; that is allocators which are designed to general case where you need allocation. arena means an allocator that doesn't require memory to be individually freed.

Now in general developers will just use the allocators provided by the standard library, but that is not required. The gpa and arena conventions are shorthands telling API consumers how the allocator will be used in this specific API.

@andrewrk andrewrk merged commit 182cdf7 into master Nov 28, 2024
10 checks passed
@andrewrk andrewrk deleted the std.ArrayHashMap branch November 28, 2024 19:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
release notes This PR should be mentioned in the release notes. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants